-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
  • 732,580
  • 175
  • 1,330
  • 1,459
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
  • 6,048
  • 9
  • 40
  • 62
-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
  • 219,104
  • 29
  • 407
  • 436