从对象类型System.Int32 []到已知的托管提供程序本机类型不存在映射

时间:2013-09-29 03:55:32

标签: c# asp.net ado.net

我在以下代码中遇到上述错误。此处listidintegers的列表。

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
}

1 个答案:

答案 0 :(得分:4)

您可以将查询更改为:

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

并删除AddWithValue()行。