Link to home
Start Free TrialLog in
Avatar of jgycy
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.ActiveConnection = cnn1
   cmdByRoyalty.CommandText = "{? = Call ValidateAssociate (?,?)}"
   cmdByRoyalty.CommandType = adCmdText
   cmdByRoyalty.CommandTimeout = 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.Append prmByRoyalty2
   cmdByRoyalty.Parameters.Append prmByRoyalty
   cmdByRoyalty.Parameters.Append 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
Avatar of boodabelly
boodabelly

A function in VB doesnt actually return a value like in C/C++, it is assigned a value that is accesible by the rest of the program.

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.
Avatar of jgycy

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.
ASKER CERTIFIED SOLUTION
Avatar of 10point
10point

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jgycy

ASKER

All I want to find out is why the return parameter value doesn't get passed back from the stored procedure.
Avatar of jgycy

ASKER

All I want to find out is why the return value from the stored procedure isn't being returned back through prmByRoyalty2.value.