Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OUTPUT parameter variable in Stored Proc expects a value

Status
Not open for further replies.

whool

Programmer
Jan 31, 2002
31
AU
Dear clever commrades,

I am trying to excute an sp on SQLSvr200 from VB using ADO. The sp has two input parameters and one OUTPUT param. I am passing the two input parameters but SQL Server seems to be expecting the OUTPUT param as well.

The SP:

ALTER PROC uspTest

(@OP int OUTPUT,
@Listid Varchar(40),
@Description varchar (40))
AS
--UPDATE statement etc....
__________________________________

VB:

Sub Testsp()

Dim cmd As New ADODB.Command
Dim prmlistID As New ADODB.Parameter
Dim prmDesc As New ADODB.Parameter
Dim prmOUT As New ADODB.Parameter


With prmOUT
.Name = "@OP"
.Type = adInteger
.Direction = adParamReturnValue
End With
cmd.parameters.Append prmOUT

With prmlistID
.Name = "@ListID"
.Value = ListID
.Type = adVarChar
.Size = 38
.Direction = adParamInput
End With
cmd.parameters.Append prmlistID

With prmDesc
.Name = "@Description"
.Value = ListDescription
.Type = adVarChar
.Size = 38
.Direction = adParamInput
End With
cmd.parameters.Append prmDesc

With cmd
.ActiveConnection = g_cn
.CommandType = adCmdStoredProc
.CommandText = m_spName
.Execute 'Fails Here!
End With

End Sub



The code fails at cmd.execute and I get the error from SQLSrv :"...Error converting Datatype Varchar to Int." SQL seems to fill its param variables from left to right, which is fair enough but what if the first one is an OUTPUT param variable as in my example?? Or am I misunderstaning the meaing of the SQL OUTPUT reserved word .
Any help much appreciated.

Yael Wasserman


 
You are using the wrong option on the variable that is an expected output. The return from SQL Server is an integer and adParamReturnValue is telling SQL Server that this is a return code not an output parameter. Also, when you send adParamReturnValue it must be the first parameter in the list which you are doing so this is another indication to SQL Server that this is the return code.

With prmOUT
.Name = "@OP"
.Type = adInteger
.Direction = adParamReturnValue
End With
cmd.parameters.Append prmOUT

This can be
.Direction = adParamOutput
or
.Direction = adParamInputOutput
 
Take a look at these resources.

Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top