tags:

views:

66

answers:

3

Consider a DataTable which contains columns:

  RefID : string  
RefName : string 
RefDate : DateTime

The DataTable does not contains any primary key.

I have another List<string> named ExcludeMe.

I would like to filter my DataTable and exclude all of the rows where values in RefId Column around found in the ExcludeMe list.

How can I achieve this using LINQ?

+1  A: 

something like:

dt.Rows.Cast<DataRow>.Where(s => !excludeMe.Contains(s["RefID"].ToString()));

Haven't tried to yet.

Jaime
+1  A: 

I have not tried it but someting like this should work.

var out = dataTable.Where(x => excludeMe.contains(x.RefId);
var filtered = dataTable.Except(out);
schoetbi
+1  A: 

Try this

DataRow[] filterred = RefDataTable.AsEnumerable()
.Where(row => !ExcludeMe.Contains(row["RefID"].ToString()))
.ToArray();
Roland