Select unique rows from 2 DataTables and store them to the 3rd DataTable

Hello,
I’ve got 2 DataTables with the same structure.
I need to select all the unique rows form dt1 that are not presents in dt2 and store them to dt3.
Then I need to select all the unique rows form dt2 that are not presents in dt1 and concatenate them to dt3.
Which is the most performant way to perform this task ?

when no duplicates are present and all cols are to compare we can use set operations

dt3 = dt1.AsEnumerable.Except(dt2.AsEnumerable, DataRowComparer.Default).CopyToDataTable

otherwise we could use a custom LINQ

here swap above
dt4 = dt2AsEnumerable.Except(dt1.AsEnumerable, DataRowComparer.Default).CopyToDataTable

so dt3, dt4 can be later merged

Thank you very much @ppr.
Is there any method to groupe a DataRow by all its columns ?

we would recommend to open a new topic as it is a new case.

One of a few techniques is a GroupBy and an dynamic concatenated String over all cols as a single group by key

How to merge multiple DataTables avoiding the ‘Merge Data Table’ activity ?

we would use it.

For learning purpose can be tried.
grafik

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