handle out parameters
public static long callproc()
{
DbCommand command = db.GetStoredProcCommand("dbo.proc");
db.AddOutParameter(command, "@proc_id", DbType.Int64, 8);
db.ExecuteNonQuery(command);
return long.Parse(db.GetParameterValue(command, "@proc_id").ToString());
}
Is this the 开发者_C百科best way to use out parameter?
The function GetParameterValue() is not part of the .NET framework, so I'm not sure what it does.
In any case, it looks like you're converting a SqlInt64 to string and then to a long. This will work, but it's the long way around. There is an implicit conversion between SqlInt64 and long. Try:
return (long) command.Parameters["@proc_id"].Value;
This avoids the need for an intermediate string.
加载中,请稍侯......
精彩评论