I need to compare a list with Datatable and filter values using Linq
I need to compare a list against a Datatable column and return the result as values from the list that are not present in the DataTable.
List:
DataTable:
Here I need to compare the list against the Datable User Id column and return the result from the list not present in the DataTable.
For example IMS022 and IMS029 are present in the list and not present in Datable.Hence I have to get IMS022, IMS029 as filter result
Thank you in advance
+3
Arun D
source
to share
2 answers
You can do
var result = list.Except(dataTable.AsEnumerable().Select(x => x["User Id"]));
You need to import the namespace System.Linq
to use Except
.
+3
Nikhil Agrawal
source
to share
var result=Items.Except(datatable.AsEnumerable().Select(r => r.UserID<string>(columnIndex)));
Hope it helps!
0
mounika
source
to share