gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:41:32 24 4
gpt4 key购买 nike

我在以下代码中遇到上述错误。这里的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com