嗨,作为学习的一部分,我正在研究 mvc,所以我遇到了一种情况,我必须将数据表传递给 sp,同时我必须提供一个 int 的输出参数
也是类型。目前我正在使用此代码
con.Execute("XXXXXXX",
new { @LoginId = LoginId, @City= City, @RegionCode = RegionCode, @CarList= Cars, @CompCOde = COmp},
commandType: CommandType.StoredProcedure);
这里的 Cars 是一个数据表,所以我想为此添加一个输出参数,请建议我一个解决方案。
最佳答案
我将创建一个参数列表,其中一个指定为 ParameterDirection.Output
,然后您将能够使用 Get
从中读取内容。
我对以下示例做了一些假设,包括 int 输出参数(未测试)
SqlConnection con = new SqlConnection();
DynamicParameters p = new DynamicParameters();
p.Add("@LoginId", LoginId, dbType: DbType.VarNumeric, direction: ParameterDirection.Input);
p.Add("@City", City, dbType: DbType.VarNumeric, direction: ParameterDirection.Input);
p.Add("@RegionCode", RegionCode, dbType: DbType.VarNumeric, direction: ParameterDirection.Input);
p.Add("@CarList", Cars.AsTableValuedParameter());
p.Add("@SomeId", dbType: DbType.Int32, direction: ParameterDirection.Output);
con.Execute("XXXXXXX",p,commandType: CommandType.StoredProcedure);
int someId = p.Get<int>("@SomeId");
关于asp.net-mvc-4 - 使用 dapper 将输出参数传递给接受数据表作为参数的 sp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43463174/