Reading output parameter from stored procedure......

  • Thread starter Thread starter Gish Smith
  • Start date Start date
G

Gish Smith

In my ADO.Net coding I am using SQLCommand and SQLParameter to run stored
procedure. Can any one advice me how to read the output parameter from a
stored procedure. I am using SQL Server 2000.
Gish Smith
 
thanks

Anatoly said:
It's easy one:

SqlCommand cmd = new SqlCommand("sp_...", myConnection);
cmd.Parameters.Add("@myInputParam", SqlDbType.Char, 20).Value =
"myStringValue";
cmd.Parameters.Add("@myOutputParam", SqlDbType.Int).Direction =
ParametersDirection.Output;
myConnection.Open()
cmd.ExecuteNonQuery()
//here it come:
int ReturnValue = cmd.Parameters["@myOutputParam"].Value;
myConnection.Close();

HTH

Gish Smith said:
In my ADO.Net coding I am using SQLCommand and SQLParameter to run stored
procedure. Can any one advice me how to read the output parameter from a
stored procedure. I am using SQL Server 2000.
Gish Smith
 
It's easy one:

SqlCommand cmd = new SqlCommand("sp_...", myConnection);
cmd.Parameters.Add("@myInputParam", SqlDbType.Char, 20).Value =
"myStringValue";
cmd.Parameters.Add("@myOutputParam", SqlDbType.Int).Direction =
ParametersDirection.Output;
myConnection.Open()
cmd.ExecuteNonQuery()
//here it come:
int ReturnValue = cmd.Parameters["@myOutputParam"].Value;
myConnection.Close();

HTH
 
Back
Top