开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜