Linq query to compare 2 datatable and get matching rows

Hi All,

I have 2 datatable
DT1 :
Name Role
AAA IT
BBB Customer Executive

DT2 :
Name Role
AAA IT
CCC Admin
BBB Customer Executive

I need to retrieve matching records

Final result :
Name Role
AAA IT
BBB Customer Executive

Hi @divya_Bhat , firstly welcome!.

After reading your question, here is the code. Use Intersect it will get the require common rows
image

dt1.AsEnumerable().Intersect(dt2.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable
2 Likes

@pavithra_pavi for quick help!, i was in need of urgent help. Code works !!! :slight_smile: :grin:

1 Like

@divya_Bhat , happy to help!

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