How to compare two data tables & copy uncommon rows to other datatable?

I have dt1 with 1 row
dt2 with 10 rows
need to compare those 2 data tables & fetch 1 row from dt1 & remove in dt2 .After that copy that dt2 into another data table i.e dt3.
Please help

@vnsatyasunil

Read Range (dt1) → Read Range (dt2) → Join Data Table (Inner Join, based on common key) → Remove Data Row (from dt2) → Assign (Copy dt2 to dt3)

Please refer this solution

Hi,
You can use for loop and if to compare 2 dt
Then build new dt3 to assign
You can share your dt1 and dt2
Regards,

Hi @vnsatyasunil

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

dt3 will have only uncommon rows.

Hope it helps.

2 Likes

Hi @vnsatyasunil

Use the below linq expression

dt_UnCommonRows = dt1.AsEnumerable().Except(dt2.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable

Hope it helps!!

2 Likes

Hey @vnsatyasunil

Use join datatable activity
image

Hi @vnsatyasunil

Please find the below xaml for your refernece.

Data Table.xaml (11.1 KB)

Output : DataTable.xlsx (6.8 KB)

I hope it helps!!

1 Like

@vnsatyasunil

If you found the solution for your query. Please mark it as solution to close the thread.

Regards,

If you find the solution for your query Make mark it as solution which help to other forum members.

Happy Automation @vnsatyasunil !!

row is not deleting from datatable

@vnsatyasunil

Tyr using below xaml

Main.xaml (11.5 KB)

not able to open document error coming while opening shared xaml file. Please share again

@vnsatyasunil

dt1 with 1 row
dt2 with 10 rows
then
dt3=dt2.AsEnumerable().Except(dt1.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable

if

dt2 with 1 row
dt1 with 10 rows
then
dt3=dt1.AsEnumerable().Except(dt2.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable

yes tried that way only in dt3 all 10 rows coming 9 should come by deleting 1 row right?

@vnsatyasunil

Forum.zip (15.0 KB)

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