SQL中有个IN 集合,怎么传递参数啊
问个简单问题.string s="SELECT * FROM USER U WHERE U.ID IN(@ID)"
ADO 怎么添加这个集合参数?
string[] s = { "58", "59", "60" };
StringBuilder strBuilder = new StringBuilder();
strBuilder.Append("select *from T_Helicopter as h ");
strBuilder.Append(" Where 1=1 and h.Id in ('"+s.ToString()+"'");
SQLiteParameter[] parameters = { new SQLiteParameter("id", "58") };
DataTable table = SQLiteDBHelper.ExecuteDataTable(strBuilder.ToString(), null);
--------------------编程问答-------------------- string[] s = { "58", "59", "60" };
↓
string s = "58,59,60"; --------------------编程问答-------------------- string str = "'" + "58" + "'" + "," + "'" + "'" + "59" + "'" + "," + "'" + "60" + "'";
"in (" + str + ")" --------------------编程问答--------------------
不行.IN语句这块不正确.如果采用拼接字符串,应该是IN ('58','59','60').
我现在是不想用拼接字符串,能否在传参给引用变量(@ID)时,直接给LIST? --------------------编程问答--------------------
[code=csharp]
string.Join(",",s)
[/code] --------------------编程问答-------------------- 改一句
strBuilder.Append(" Where 1=1 and h.Id in ('"+String.Join(",",s)+"'"); --------------------编程问答-------------------- 难道就没有直接传LIST参数的方法吗?都是组装成字符串拼接....... --------------------编程问答--------------------
MS 这样仍然不行.用JOIN出来的是'XX,XX,XX',而不是'XX','XX','XX'. --------------------编程问答-------------------- String.Join("','",s)
补充:.NET技术 , C#