我在以下代码中遇到上述错误。这里的 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
}
最佳答案
您可以将查询更改为:
SqlCommand cmd = new SqlCommand (String.Format ("SELECT * FROM status WHERE uid IN ({0})", String.Join (",", listid)));
并删除 AddWithValue() 行。
关于c# - 不存在从对象类型 System.Int32[] 到已知托管提供程序 native 类型的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19074226/