Get item in column same value between 2 datatable

Hi Everyone.

I want to compare 2 datatables ( Sheet1, Sheet2 ) as attached file to got “item” duplicate without loop row by row from each datatable.

As attached file, i will get new a datatable contains “item” duplicate as below:

D
E

How to do this by LinQ

Thanks in advance!
Book1.xlsx (8.8 KB)

Hi,

Can you try the following expression?

dt1.AsEnumerable.Select(Function(r) r("item").ToString).Intersect(dt2.AsEnumerable.Select(Function(r2) r2("Item").ToString)).ToArray

Regards,

1 Like

Hi Bro.

Thanks you very much.

But i have another small question.

After found duplicate items ( “Item” Column ) in 2 datatables… how to remove rows in Sheet2 which has item in “item” column same with sheet1 .

It’s mean will remove rows in Sheet2 if has any item in “item” column same with Sheet1

Thanks in advance!

Hi

How about the following?

dt2 = dt2.AsEnumerable.Where(Function(r2) not dt1.AsEnumerable.Select(Function(r1) r1("Item").ToString).Contains(r2("Item").ToString)).CopyToDataTable

Regards,

1 Like

Thanks you very much Bro!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.