1

我在以下代码中遇到了上述错误。这listid是一个列表integers

SqlConnection cn = new SqlConnection(str1);
SqlCommand cmd = new SqlCommand("select * from status where uid in {@values}", cn);
cn.Open();
cmd.Parameters.AddWithValue("@values",listid.ToArray())
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
//code here
}
4

1 回答 1

3

您可以将查询更改为:

SqlCommand cmd = new SqlCommand (String.Format ("SELECT * FROM status WHERE uid IN ({0})", String.Join (",", listid)));

并删除 AddWithValue() 行。

于 2013-09-29T04:08:48.460 回答