C# select from in ("++") 问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 04:31:41
SqlCommand MyCmd = new SqlCommand("select count(id) as co from Hu_product where cid in (" + proidlist + ")", conn);

cid 是 int 字段。

我想知道 proidlist 应该定义成 数组 还是 ?

标准Sql语句写法为:
select * from Hu_product where cid in(3,5,6,1,2)

所以proidlist定义成string类型,传递以,间隔的数字就行如:

proidlist="1,5,6,7,9";

SqlCommand MyCmd = new SqlCommand("select count(id) as co from Hu_product where cid in (" + proidlist + ")", conn);
这样就行的。