How to: Execute a Stored Procedure using EnterPriseLibrary that Returns a Value?

Tripati.patro
Posted by Tripati.patro under C# category on | Points: 40 | Views : 15021
var selectCommand = DatabaseInstance.GetStoredProcCommand("GetReturnValue");

selectCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@anyname", DbType.Int16));
selectCommand.Parameters["anyname"].Direction = ParameterDirection.ReturnValue;

DatabaseInstance.ExecuteNonQuery(selectCommand);

var intReturnValue = Convert.ToInt64(selectCommand.Parameters["@ReturnValue"].Value);


//OR

var selectCommand = DatabaseInstance.GetStoredProcCommand("GetReturnValue");
DatabaseInstance.AddParameter(selectCommand, "anyname", DbType.Int32, ParameterDirection.ReturnValue, null, DataRowVersion.Default, null);

DatabaseInstance.ExecuteNonQuery(selectCommand);

var returnValue = Convert.ToInt32(DatabaseInstance.GetParameterValue(selectCommand, "anyname"));

Comments or Responses

Posted by: Tripati_tutu on: 2/21/2011 Level:Bronze | Status: [Member] | Points: 10
Good one...
Really this is helpful for us.


Thanks & Regards,
Tripati

Login to post response