-4

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.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
StewieHere
  • 43
  • 9

2 Answers2

0

check this SO post: Is there a “not equal” in a linq join

var filteredDataTable = tableA.Except(tableB);

Regards

Community
  • 1
  • 1
BizApps
  • 5,982
  • 8
  • 39
  • 60
-1

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;
Habib
  • 212,447
  • 27
  • 392
  • 421