I have 2 datatables.
dtTable1:
id Name
--- ----
1 AAA
2 BBB
dtTable2:
id
---
2
The output needs to be table1 without the row with id=2.
How can I do this using Linq?
Thanks in advance.
I have 2 datatables.
dtTable1:
id Name
--- ----
1 AAA
2 BBB
dtTable2:
id
---
2
The output needs to be table1 without the row with id=2.
How can I do this using Linq?
Thanks in advance.
check this SO post: Is there a “not equal” in a linq join
var filteredDataTable = tableA.Except(tableB);
Regards
You may get a list of IDs from second DataTAble like:
var tempList = (from d in dt2.AsEnumerable()
select d.Field<int>("ID")).ToList();
Later you can use !Contains
to check Not In from the first datatable like:
var result = from t in dt1.AsEnumerable()
where !tempList.Contains(t.Field<int>("ID"))
select t;