Reputation: 24093
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 best way to use out parameter?
Upvotes: 2
Views: 2408
Reputation: 238176
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
.
Upvotes: 2