select * form table where Id in (数组的问题)

yjjone yjjone 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如题语句,三层架构,需要在 (@Ids)内传入一个数组 ,
实现的功能就是 判断哪些行被选中,然后把选中行的ID加入到数组中,然后用sql查询出对应的数据
UI 层
private void Print_Click(object sender, RoutedEventArgs e)
{
List<int> Ids= new List<int>();

List<T_CpckLibraryNO> xelementList = grd.SelectedItems.OfType<T_CpckLibraryNO>().ToList();

foreach (T_CpckLibraryNO tq in xelementList)
{
LibraryNos.Add(tq.Id);
}
string str="";
for (int i = 0; i < Ids.Count; i++)
{

str = str + Ids[i] + ","; //每个中间加逗号
}

str = str.Substring(0, str.Length - 1); //去掉最后一个逗号




DAL 层
public DataTable getbyid(string Ids)
{
DataTable table = SqlHelper.ExecuteDataTable("select * from T_CpckLibraryNO where Ids in (@Ids) ", new SqlParameter("@Ids", Ids));


if (table.Rows.Count <= 0)
{
return null;
}
else if (table.Rows.Count == 1)
{
return table;
}
else
{
throw new Exception();
}
}


变量str 传进去 被识别为 “” 多了两个引号,所以一直查不到数据了 难道要把 str变量 转换成其他类型?
请问该如何取消引号 搜索了下论坛都没试验成功
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
yjjone
WPF/Silverlight 8,757 成员 12,031 内容