Below is a code sample and the SP. Basically I am returning the number of records returned by the SP so that I can handle the recordset to fill a flex grid and set it up with the appropriate number of rows etc....
Thanks !!
Here is a Code Sample:
Private Sub Command1_Click()
Dim objCon As ADODB.Connection
Dim objCom As ADODB.Command
Dim objPara As ADODB.Parameter
Dim objpara2 As ADODB.Parameter
Dim objRS As ADODB.Recordset
Dim k As Integer
Dim values(1) As Integer
Set objCon = New ADODB.Connection
Set objCom = New ADODB.Command
'Creating the DB connection string
'Please change the below connection string as per your server and database being used.
objCon.ConnectionString = "!!!!!CONN STRING HERE !!!!"
'Opening the connection
objCon.Open objCon.ConnectionString
MsgBox "Connection opened"
'assigning the command object parameters
With objCom
.CommandText = "p_gui_GetJobProcess" 'Name of the stored procedure
.CommandType = adCmdStoredProc 'Type : stored procedure
.ActiveConnection = objCon.ConnectionString
End With
'Create 2 output parameters
Set objPara = objCom.CreateParameter("@JobID", adChar, adParamInput, 4, "0008")
Set objpara2 = objCom.CreateParameter("@pcnt", adInteger, adParamOutput)
'Append the output parameters to command object
objCom.Parameters.Append objPara
objCom.Parameters.Append objpara2
'Store the result in a recordset
Set objRS = objCom.Execute
'MsgBox "Total records returned: " & objpara2.Value
'Open the recordset
Do While Not objRS.EOF
For k = 0 To objRS.Fields.Count - 1
Debug.Print objRS(k).Name & ": " & objRS(k).Value
Next
Debug.Print "_____"
objRS.MoveNext
Loop
'**** COMMENT THE FOLLOWING LINE OUT TO GET A VALUE RETURNED FOR THE OUT-PARAM, while being executed no values are returned....****
values(0) = objpara2.Value
'Close the recordset
objRS.Close
values(1) = objpara2.Value
'retrieve the output parameters values
MsgBox objPara.Value
MsgBox "Total records returned: Pre=" & values(0) & ";PostA=" & values(1)
'close connection
objCon.Close
'cleaning up
Set objCom = Nothing
Set objCon = Nothing
Set objPara = Nothing
Set objpara2 = Nothing
Set objRS = Nothing
End Sub
and here is the SP:
create proc dbo.p_gui_GetDBProcess
(@DBName varchar(30),
@pcnt int output)
as
/*db processes by way of job header, read only*/
select a.ProcessID, a.JobID, a.ExecType, a.rExecute, a.UseParams
from Job_Process a,
Job_Header b
where b.DBName = @DBName
and a.JobID = b.JobID
select @pcnt = @@rowcount