Reputation: 15431
I need to get the value returned from a stored procedure in my Sql Server db.a This store procedure using a return statement to return a value back to the app.
I need to retrieve this value in C#. How do i get this value?
Note:
I also know i can use a output variable.
What is don't know is how to retrieve the value returned from a return statement in my sp.
How do i get it done? I am avoid make a lot of change.
Update:
I'm using SQLHelper.
Upvotes: 4
Views: 1295
Reputation: 48088
Set your return parameter's Direction
property to ParameterDirection.ReturnValue
, and after you execute your command get return parameter's value like that :
SqlParameter myReturnParam = command.Parameters.Add("@MyReturnValue",
SqlDbType.Int);
myReturnParam.Direction = ParameterDirection.ReturnValue;
// Execute your Command here, and get the value of your return parameter :
int myReturnValue = (int)command.Parameters["@MyReturnValue"].Value;
Upvotes: 3