select * form table where Id in (数组的问题)
如题语句,三层架构,需要在 (@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变量 转换成其他类型?
请问该如何取消引号 搜索了下论坛都没试验成功
实现的功能就是 判断哪些行被选中,然后把选中行的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变量 转换成其他类型?
请问该如何取消引号 搜索了下论坛都没试验成功
...全文
相关推荐
ABAP最详细的开发规范
ABAP开发规范,写得较为详细,对于初学者值得一看。
mysql 一个较特殊的问题:You can't specify target table 'wms_cabinet_form'
mysql 一个较特殊的问题:You can't specify target table 'wms_cabinet_form' for update in F
mysql 一个较特殊的问题:You can’t specify target table ‘wms_cabinet_form’
今天在写 mysql 遇到一个比较特殊的问题。 mysql 语句如下: update wms_cabinet_form set cabf_enabled=0 where cabf_id in ( SELECT wms_cabinet_form.cabf_id FROM wms_cabinet_form Inner Join wms_cabinet ON wms_cabinet_form.cabf_cab_id = wms_cabinet.cab_id Inner Join wms_cabinet_row ON wms_cabinet.cab_row_id =wms_cabinet_row.ro
Oracle常见问题的解决方法
Oracle常见问题的解决方法 Oracle 常见问题
一些搞笑的sql语句
总结的一些高效的sql语句,希望对童鞋们有所帮助!


