日期:2014-05-20  浏览次数:20449 次

asp.net程序里如何得到存储过程的output参数的值
asp.net程序里如何得到存储过程的output参数的值!   请详细说明   谢谢     给个列子也可以

------解决方案--------------------
SqlCommand cmd = new SqlCommand( "hyproc1 ", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter( "@sal ", SqlDbType.Float));
cmd.Parameters.Add(new SqlParameter( "@Num ", SqlDbType.Int));
cmd.Parameters[0].Value = 110000;
cmd.Parameters[1].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
Console.WriteLine(cmd.Parameters[1].Value.ToString());
------解决方案--------------------
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings[ "DBConn "]);
SqlCommand cmdSelect = new SqlCommand( "KL_GetInvestCode ", conn);
cmdSelect.CommandType = CommandType.StoredProcedure;

SqlParameter sp = cmdSelect.Parameters.Add( "@NewCode ", SqlDbType.NVarChar, 0, "NewCode ");
sp.Direction = ParameterDirection.Output;
try
{
object a = cmdSelect.ExecuteScalar();
return cmdSelect.Parameters[ "@NewCode "].Value.ToString();
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
------解决方案--------------------
SqlConnection conn = new sqlConnection(conStr);

Sqlcommand cmd = new SqlCommand( "存储过程名 ",conn);

SqlParameter paramOut = cmd.Parameters.Add( "@Return_Value ", " ");
paramOut.Direction = ParameterDirection.ReturnValue;

conn.open();
cmd.ExecuteNonQuery();
int i = (int)cmd.Parameters[ "@Return_Value "].value;
------解决方案--------------------
伪代码:
SqlConnection _conn = new SqlConnection( "…… ");
SqlCommand _comm = new SqlCommand( "存储过程名 ", _conn );
......
_comm.Parameter( "@Param ", SqlDbType.类型 ).Direction = ParameterDirection.Output;

_comm.ExecuteNonQuery();

string strValue = _comm.Parameter[ "@Param "].Value.ToString();