c# – 如何将参数传递给sql’in’语句?
发布时间:2020-12-15 06:57:52 所属栏目:百科 来源:网络整理
导读:我想创建这个查询: select * from products where number in ('123','234','456'); 但我找不到任何与Npgsql和NpgsqlParameter一起使用的示例.我试过这样: string[] numbers = new string[] { "123","234" };NpgsqlCommands cmd = new NpgsqlCommands("sele
我想创建这个查询:
select * from products where number in ('123','234','456'); 但我找不到任何与Npgsql和NpgsqlParameter一起使用的示例.我试过这样: string[] numbers = new string[] { "123","234" }; NpgsqlCommands cmd = new NpgsqlCommands("select * from products where number in (:numbers)"); NpgsqlParameter p = new NpgsqlParameter("numbers",numbers); command.Parameters.Add(p); 但它没有工作;) 解决方法
将其作为数组传递:
string[] numbers = new string[] { "123","234" }; NpgsqlCommands cmd = new NpgsqlCommands("select * from products where number = ANY(:numbers)"); NpgsqlParameter p = new NpgsqlParameter("numbers",NpgsqlDbType.Array | NpgsqlDbType.Text); p.value = numbers; command.Parameters.Add(p); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |