我想创建这个查询:
@H_502_2@select * from products where number in ('123','234','456');
但我找不到任何与Npgsql和NpgsqlParameter一起使用的示例.我试过这样:
@H_502_2@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);但它没有工作;)
解决方法
将其作为数组传递:
@H_502_2@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);