在asp.net中如何得到存储过程反回值.

解决方案 »

  1.   

    add ParameterDirection.ReturnValue type parameter, if you are using DataReader, you need to close it first, seehttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingstoredprocedureswithcommand.aspSqlCommand sampleCMD = new SqlCommand("SampleProc", nwindConn);
    sampleCMD.CommandType = CommandType.StoredProcedure;SqlParameter sampParm = sampleCMD.Parameters.Add("RETURN_VALUE", SqlDbType.Int);
    sampParm.Direction = ParameterDirection.ReturnValue;sampParm = sampleCMD.Parameters.Add("@InputParm", SqlDbType.NVarChar, 12);
    sampParm.Value = "Sample Value";sampParm = sampleCMD.Parameters.Add("@OutputParm", SqlDbType.NVarChar, 28);
    sampParm.Direction = ParameterDirection.Output;nwindConn.Open();SqlDataReader sampReader = sampleCMD.ExecuteReader();Console.WriteLine("{0}, {1}", sampReader.GetName(0), sampReader.GetName(1));while (sampReader.Read())
    {
      Console.WriteLine("{0}, {1}", sampReader.GetInt32(0), sampReader.GetString(1));
    }sampReader.Close();
    nwindConn.Close();Console.WriteLine(" @OutputParm: {0}", sampleCMD.Parameters["@OutputParm"].Value);
    Console.WriteLine("RETURN_VALUE: {0}", sampleCMD.Parameters["RETURN_VALUE"].Value);
      

  2.   

    command.Parameters.Add("@abc", SqlDbType.VarChar, 200);
    command.Parameters("@abc").Direction = ParameterDirection.Output;...connection.Open();
    command.ExecuteNonQuery();
    connection.Close();...string abc = command.Parameters("@abc").Value.ToString();