Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //the name of the stored proc is TEST1
  2. SqlCommand myCommand = new SqlCommand("TEST1", myConnection);
  3.  
  4. //Tell the command its a stored procedure, not regular SQL
  5. myCommand.CommandType = CommandType.StoredProcedure;
  6.  
  7. //Add a parameter to the command
  8. int i=0;
  9. myCommand.Parameters.AddWithValue("@result",i);
  10.  
  11. //tell it that this parameter is a return value, not a regular inbound parameter
  12. myCommand.Parameters["@result"].Direction = ParameterDirection.ReturnValue;
  13.  
  14. //now execute
  15. try
  16. {
  17.     myCommand.ExecuteNonQuery();
  18. //nor retrieve the value in the return parameter.
  19.     i = (int)myCommand.Parameters["@result"].Value;
  20.  
  21.