Return value from a Stored Procedure

Akiii
Posted by Akiii under Sql Server category on | Points: 40 | Views : 2095
This is how we can get the return value from a stored procedure :-

SqlParameter paramReturnValue = new SqlParameter();
paramReturnValue.ParameterName = "@RETURN";
paramReturnValue.Direction = ParameterDirection.Output;

...

conn.Open();
cmd.Connection = conn;
cmd.ExecuteNonQuery();

...

int returnValue = (int)cmd.Parameters["@RETURN"].Value;



Thanks and Regards
Akiii

Comments or Responses

Posted by: Vuyiswamb on: 7/27/2012 Level:NotApplicable | Status: [Member] [MVP] [Administrator] | Points: 10
You are missing the Important part. in your StoredProcedure you must have an output parameter else this is not going to work
Posted by: Akiii on: 7/27/2012 Level:Bronze | Status: [Member] | Points: 10
Yes of course Sir.

Output parameter is needed otherwise the value will not be returned. It is written as :-

@RETURN int output




Thanks and Regards
Akiii
Posted by: Vuyiswamb on: 7/27/2012 Level:NotApplicable | Status: [Member] [MVP] [Administrator] | Points: 10
That is Good

Login to post response