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: Comparison list

DataTable: Datable to compare

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
list c # filter linq datatable


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


source to share


var result=Items.Except(datatable.AsEnumerable().Select(r => r.UserID<string>(columnIndex)));

      



Hope it helps!

0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics