jgycy
asked on
VB6 ADO - Return Parameters
I'm trying to retrieve a return value from a stored procedure that is executed through ADO. Nothing is being returned from the stored procedure in prmByRoyalty2.value.
A similiar procedure written in RDO works.
Any help will be appreciated!
VB CODE USED TO EXECUTE STORED PROCEDURE
Dim cnn1 As ADODB.Connection
Dim cmdByRoyalty As ADODB.Command
Dim prmByRoyalty As ADODB.Parameter
Dim prmByRoyalty1 As ADODB.Parameter
Dim prmByRoyalty2 As ADODB.Parameter
Dim rstByRoyalty As ADODB.Recordset
Dim intRoyalty As Integer
Dim strAuthorID As String
Dim strCnn As String
' Define a command object for a stored procedure.
Set cnn1 = New ADODB.Connection
strCnn = "uid=jxgong;pwd=;dsn=cargo ;"
cnn1.Open strCnn
Set cmdByRoyalty = New ADODB.Command
Set cmdByRoyalty.ActiveConnect ion = cnn1
cmdByRoyalty.CommandText = "{? = Call ValidateAssociate (?,?)}"
cmdByRoyalty.CommandType = adCmdText
cmdByRoyalty.CommandTimeou t = 15
' Define the stored procedure's input parameter.
Set prmByRoyalty = New ADODB.Parameter
prmByRoyalty.Type = adChar
prmByRoyalty.Size = 6
prmByRoyalty.Direction = adParamInput
prmByRoyalty.Value = "jxgong"
' Define the stored procedure's input parameter.
Set prmByRoyalty1 = New ADODB.Parameter
prmByRoyalty1.Type = adChar
prmByRoyalty1.Size = 6
prmByRoyalty1.Direction = adParamInput
prmByRoyalty1.Value = "jxgong"
' Define the stored procedure's input parameter.
Set prmByRoyalty2 = New ADODB.Parameter
prmByRoyalty2.Type = adInteger
prmByRoyalty2.Size = 1
prmByRoyalty2.Direction = adParamReturnValue
cmdByRoyalty.Parameters.Ap pend prmByRoyalty2
cmdByRoyalty.Parameters.Ap pend prmByRoyalty
cmdByRoyalty.Parameters.Ap pend prmByRoyalty1
' Create a recordset by executing the command.
Set rstByRoyalty = New Recordset
rstByRoyalty.Open Source:=cmdByRoyalty
debug.print prmByRoyalty2.value
cnn1.Close
STORED PROCEDURE:
IF EXISTS(SELECT * FROM POLICY WHERE POLICYNBR = 'JC00000')
RETURN 1
ELSE
RETURN 0
A similiar procedure written in RDO works.
Any help will be appreciated!
VB CODE USED TO EXECUTE STORED PROCEDURE
Dim cnn1 As ADODB.Connection
Dim cmdByRoyalty As ADODB.Command
Dim prmByRoyalty As ADODB.Parameter
Dim prmByRoyalty1 As ADODB.Parameter
Dim prmByRoyalty2 As ADODB.Parameter
Dim rstByRoyalty As ADODB.Recordset
Dim intRoyalty As Integer
Dim strAuthorID As String
Dim strCnn As String
' Define a command object for a stored procedure.
Set cnn1 = New ADODB.Connection
strCnn = "uid=jxgong;pwd=;dsn=cargo
cnn1.Open strCnn
Set cmdByRoyalty = New ADODB.Command
Set cmdByRoyalty.ActiveConnect
cmdByRoyalty.CommandText = "{? = Call ValidateAssociate (?,?)}"
cmdByRoyalty.CommandType = adCmdText
cmdByRoyalty.CommandTimeou
' Define the stored procedure's input parameter.
Set prmByRoyalty = New ADODB.Parameter
prmByRoyalty.Type = adChar
prmByRoyalty.Size = 6
prmByRoyalty.Direction = adParamInput
prmByRoyalty.Value = "jxgong"
' Define the stored procedure's input parameter.
Set prmByRoyalty1 = New ADODB.Parameter
prmByRoyalty1.Type = adChar
prmByRoyalty1.Size = 6
prmByRoyalty1.Direction = adParamInput
prmByRoyalty1.Value = "jxgong"
' Define the stored procedure's input parameter.
Set prmByRoyalty2 = New ADODB.Parameter
prmByRoyalty2.Type = adInteger
prmByRoyalty2.Size = 1
prmByRoyalty2.Direction = adParamReturnValue
cmdByRoyalty.Parameters.Ap
cmdByRoyalty.Parameters.Ap
cmdByRoyalty.Parameters.Ap
' Create a recordset by executing the command.
Set rstByRoyalty = New Recordset
rstByRoyalty.Open Source:=cmdByRoyalty
debug.print prmByRoyalty2.value
cnn1.Close
STORED PROCEDURE:
IF EXISTS(SELECT * FROM POLICY WHERE POLICYNBR = 'JC00000')
RETURN 1
ELSE
RETURN 0
ASKER
I'm not talking about regular functions as you can see from my sample code.
I'm talking about executing a stored procedure using ADO and actually getting the value from the RETURN statement.
I'm talking about executing a stored procedure using ADO and actually getting the value from the RETURN statement.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
All I want to find out is why the return parameter value doesn't get passed back from the stored procedure.
ASKER
All I want to find out is why the return value from the stored procedure isn't being returned back through prmByRoyalty2.value.
Public Function DoSomething() as Integer
If Exists
DoSomething = 1
Else
DoSomething = 0
End Function
Hope this is written clear enough, if not please let me know.