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!

Stored Procedures

Status
Not open for further replies.

sroberts82

Programmer
Oct 11, 2005
36
US

Hi,
I have a stored procedure and it looks like the following

ALTER PROCEDURE USP_NCUInsertContentCodeTest
@var1 int,
@var2 int
etc

AS

DECLARE @RC int

//Do stuff

RETURN @RC

I know how to execute the procedure in c# but I cant figure out how to get the return value. I know if I declared the @RC before the AS I could declare it as a parameter with parameterdirectio = output etc but I cannot change the stored procedure. How can I do it?
Thank you in advance,
Ste
 
which method are you using to call it?

For a SP that returns a single integer, I would use the ExecuteScalar() method, which returns an object, which I would then cast to an integer.
 
Try adding a parameter to your command object with ParameterDirection = ReturnValue.


ocmd.Parameters.Add("RETURN", ..., ParameterDirection.ReturnValue, ...)

ocmd.Execute...

int value = (int)ocmd.Parameters["RETURN"];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top