Search code examples
c#linqdatatablelinq-to-dataset

How to filter a DataTable by values not contained in an array?


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


Solution

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