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变量 转换成其他类型?
请问该如何取消引号 搜索了下论坛都没试验成功