如何通过数组中未包含的值过滤DataTable?

时间:2012-02-21 13:57:02

标签: c# linq datatable linq-to-dataset

如果我有一个DataTable userwidget,其中包含以下列:

process_id,emp_num,widget_color

如何根据以下条件使用DataTable过滤此LINQ


1- WHERE emp_num = ...

2-和process_id NOT IN (process)//process is an array of intgers

2 个答案:

答案 0 :(得分:4)

var filtered = (from row in tbl.AsEnumerable()
               where row.Field<int>("emp_num")==yourNum
               && !process.Contains(row.Field<int>("process_id"))
               select row).CopyToDataTable();

答案 1 :(得分:1)

使用,where <list>.Contains( <item> )

 var lstprocessid = {1, 2, 3};
  var   rows =
        (from datatable in dtDetails.AsEnumerable()
          where !lstprocessid.Contains(int.parse((datatable["process_id "]).ToString())
              &&  int.parse((datatable["emp_num"]).ToString())== myemp_num     
                     select datatable).ToList<DataRow>();