如何从存储过程中获取标量输出?当我执行以下语句时,它返回DBNull。
我们正在使用ServiceStack.OrmLite 4.5.8
var le = db.<<SP Name>>(param1, param2)
.TryGetParameterValue("output_id", out object val);
OrmLite T4模板生成以下代码:
public static OrmLiteSPStatement SPName(this IDbConnection db, string @Param1 = null, string @Param2 = null, @Output_id = null)
{
var dbCmd = (DbCommand)OrmLiteConfig.ExecFilter.CreateCommand(db).ToDbCommand();
dbCmd.CommandText = "SP NAME";
dbCmd.CommandType = CommandType.StoredProcedure;
dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"Param1",@param1,ParameterDirection.Input,DbType.AnsiString));
dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"Param2",@param2,ParameterDirection.Input,DbType.AnsiString));
dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"Output_id",@output_id,ParameterDirection.InputOutput,DbType.Int32));
dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"__ReturnValue",0,ParameterDirection.ReturnValue,DbType.Int32));
return new OrmLiteSPStatement(db, dbCmd);
}
由于 rudrvij
答案 0 :(得分:1)
var result = db.Scalar<int>("EXEC [SP Name] @param1, @param2", new { param1 = "value1", param2 = "value2" });