1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| // Assumes that connection is a valid SqlConnection object.
SqlCommand command = new SqlCommand("SampleProc", connection);
command.CommandType = CommandType.StoredProcedure;
SqlParameter parameter = command.Parameters.Add(
"RETURN_VALUE", SqlDbType.Int);
parameter.Direction = ParameterDirection.ReturnValue;
parameter = command.Parameters.Add(
"@InputParm", SqlDbType.NVarChar, 12);
parameter.Value = "Sample Value";
parameter = command.Parameters.Add(
"@OutputParm", SqlDbType.NVarChar, 28);
parameter.Direction = ParameterDirection.Output;
connection.Open();
SqlDataReader reader = command.ExecuteReader();
Console.WriteLine(
"{0}, {1}", reader.GetName(0), reader.GetName(1));
while (reader.Read())
{
Console.WriteLine(
"{0}, {1}", reader.GetInt32(0), reader.GetString(1));
}
reader.Close();
connection.Close();
Console.WriteLine(" @OutputParm: {0}", command.Parameters["@OutputParm"].Value);
Console.WriteLine("RETURN_VALUE: {0}", command.Parameters["RETURN_VALUE"].Value); |
Partager