How to get the return value coming to the database using only return?

I need to get the value returned from the stored procedure in my Sql Server db.a. This storage procedure uses the return statement to return the value back to the application.

I need to get this value in C #. How to get this value?

Note:

  • I know that I can use ExecuteScalar when using "select ..." in sp to get this value.
  • I also know that I can use the output variable.

  • I don’t know how to get the value returned from the return statement in my sp.

How should I do it? I avoid big changes.

Update

I am using SQLHelper .

+4
source share
2 answers

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

See question .

+3
source

Set your Direction return value ParameterDirection.ReturnValue to ParameterDirection.ReturnValue , and after running the command, get the return parameter value:

 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; 
+3
source

All Articles