tags:

views:

77

answers:

2

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 know i can use ExecuteScalar while using "select ..." in the sp to retrieve this value.
  • 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.

+2  A: 

Add a parameter to the query using ParameterDirection.ReturnValue for the paremeder Direction property.

See this question.

Oded
You should be a lot more explicit.
Colour Blend
Could you edit your answer. It helped after all.
Colour Blend
You are asking me to be more explicit - how? What more information do you need?
Oded
+2  A: 

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;
Canavar
I'm still get 0 has the return value. I'm using SqlHelper.
Colour Blend
Ok, can you post your code ?
Canavar
+1 I've fixed it. Your code helped after all.
Colour Blend