Orson
Orson

Reputation: 15431

How do i get the return value coming a database with just using return?

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:

How do i get it done? I am avoid make a lot of change.

Update:

I'm using SQLHelper.

Upvotes: 4

Views: 1295

Answers (2)

Canavar
Canavar

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

Oded
Oded

Reputation: 499002

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

See this question.

Upvotes: 3

Related Questions