我需要就如何从vb6代码调用存储过程来检索一组状态消息以告知用户报告过程报告所处的位置提供一些指导。
商店程序的输出是:
JobOrder BatchJobTypeID Status
1 3 Previous Quarter Closed Successfully
2 1 Reporting Quarter Opened on: Feb 14 2017
我知道我可以使用For循环遍历记录集,我不确定的是,如何在一行中连接包含Status的两个单独的行。
更新
看到Zohar Peled(thx)发布的第一个答案。我继续编写子例程来完成这项任务。通过简单一瞥它,它看起来是否正确?
Private Sub Form_Load()
Dim cmd As New ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strStatus As String
strStatus = ""
On Error GoTo errhandler
Set con = New ADODB.Connection
With con
.ConnectionString = GetConnectionString("Reporting")
.Open
End With
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = con
.CommandType = adCmdStoredProc
.CommandText = "[dbo].[DisplayJobStatus]"
End With
Set rs = cmd.Execute
While Not rs.EOF
strStatus = strStatus & rs("Status")
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
End Sub
非常感谢。
答案 0 :(得分:1)
如果我没记错的话,就像这样:
Dim AllStatuses As String
AllStatuses = ""
' Declare, create and open the connection and recordset code here
While Not Rs.EOF
AllStatuses = AllStatuses & Rs("Status")
Rs.MoveNext
Loop
' Close recordset and connection here