2

If I have a DataTable userwidget, which has the following columns:

process_id, emp_num, widget_color

How to filter this DataTable using LINQ according to the following conditions:


1- WHERE emp_num = ...

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

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392

2 Answers2

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();
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
1

Use, 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>();
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263