gpt4 book ai didi

c# - Dapper 输出参数被 mysql 解释为 null

转载 作者:行者123 更新时间:2023-11-29 11:34:41 24 4
gpt4 key购买 nike

我正在尝试从 Mysql 5.6.10 (AWS Aurora) 中的测试套件运行这个简单的 Dapper 示例。

var p = new DynamicParameters(new { a = 1, b = 2 });
p.Add("c", dbType: DbType.Int32, direction:ParameterDirection.Output);
cnn.Execute(@"set @c = @a + @b", p);
var results = p.Get<int>("@c");

但是,正在引发异常。 @c 被解释为 NULL> enter image description here

我想使用两个输出参数来返回受插入语句影响的行数和最后插入的 ID。

最佳答案

我发现用dapper从mysql中获取参数似乎是不可能的,所以我修改了你的代码以达到结果。

var p = new DynamicParameters(new { a = 1, b = 2 });
//p.Add("c", dbType: DbType.Int32, direction: ParameterDirection.Output);
//conn.Execute(@"set @c = @a + @b", p);
using (var reader = conn.ExecuteReader(@"set @c = @a + @b; select @c;", p))
{
//var results = p.Get<int>("@c");
if (reader.Read())
{
var result = reader.GetInt32(0);
}
}

关于c# - Dapper 输出参数被 mysql 解释为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36819966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com