How to find rows that exist in one datatable but not the other?

I have two datatables A and B. Both have columns that have a kind of identity number. I would like to find the rows that are in datatable A but not in Datatable B by referencing the identity number columns.

What would be the best way for me to do this?

@Kamalen_Reddy

lets assume Datatable A is dtData and Datatable B is dtMaster and we want to check the first column

following LINQ can help:

(From dd In dtData.AsEnumerable
Where Not dtMaster.AsEnumerable.Any(Function (x) x(0).toString.Trim.Equals(dd(0).toString.Trim))
Select dd).toList

Find starter help here:
Find_CommonNonCommon_By1Col_AnyApproach.xaml (12.2 KB)

Thank you @ppr, what would the variable type of the output be?

Is it possible to reference the columns by column name instead of index?

@Kamalen_Reddy
it is returning a list of datarows which we can use by following pattern for a defensive copy to a datatable handling empty results:

Yes, is possible

Kindly note: refer to the linked XAML as it would answer those questions as well

Thanks @ppr, where should I go if Iā€™d like to learn more about LINQ?

1 Like

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