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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get the return code from a sql stored proceedure?

Status
Not open for further replies.

Blitz

Technical User
Jul 7, 2000
171
US
I have a stored proceedure that returns 1,2,3 or 4 depending on what happened in the proceedure. How can i get that return code back to vb.net?

I only know how to get the number of rows affected, i woudl appreciate any help. This is a little snip of the code i have:

cmdParms.Connection = sqlConn
cmdParms.CommandType = CommandType.StoredProcedure
cmdParms.CommandText = strSPName

introwsaffected = cmdParms.ExecuteNonQuery

sqlConn.Close()
Return introwsaffected


What needs to be added to get the return code?
 
I would add an output paramater to your command object and then set it the very last thing in the sp

cmdParms.Parameters.Add("@return_value", SqlDbType.int)
cmdParms.Parameters("@return_value").Direction = ParameterDirection.Output


in the sp
@return_value int output

at the end of the sp
set @return_value = value

to get the value in vb.net project
cint(cmdParms.Parameters("@return_value").value)

Hope this helps
 
ExecuteScalar is another method which can return a single value from the database.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top