我在以下代码中遇到上述错误。此处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
}
答案 0 :(得分:4)
您可以将查询更改为:
SqlCommand cmd = new SqlCommand (String.Format ("SELECT * FROM status WHERE uid IN ({0})", String.Join (",", listid)));
并删除AddWithValue()行。