How to append two datatables using Linq Query? Please help

I need to append two datatables “DT1” & “DT2”

DT1:
Column1 Column2
A 1
B 2
C 3
D 4

DT2:
Column1 Column2
E 5
F 6
G 7
H 8

What I need in DT1 after merged:

DT1:
Column1 Column2
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8

We can get the above result by using Merge Datatable activity. But I need to solve this in LinQ Query instead of using Merge Datatable activity.

Please help me

1 Like

@GuhanTM

In General IT can be understood as a dateset Operation of the Type Union.

With a linq give a try on Following

(From d in dt2.asenumerable
Let ra = d.itemarray
Select dt1.rows.add(ra)).copytodatatable

Assign this return to a variable dtTemp of datatype Datatable.

Inspect dt1 for the added rows

2 Likes

Thanks for the reply @ppr.
The code is not appending the dt2 table values.
dt1 is having dt2 contents only. Please help

Can you Share your Statements with me thanks.
Kindl Note. The dumpout to dtTemp Shows the appended rows. Dt1 has to Show all rows

Please find the file.AppendDT.xaml (8.9 KB)

@GuhanTM
Unfortunately im Off from Laptop / UiPath till monday. All my Post since Yesterday i was writing in Cellphone. In Case of you can not wait so Long so Just Put the statements Here in the Posts. I guess it is a minimal Thing aß this technique was used very often by me and worked

@ppr No Issues and I will wait.
And again Thanks for the reply

@GuhanTM
Find starter help here:
AppendDataTableOnDataTable.xaml (8.7 KB)

I did the prototype with a smaller dataset but it was running with the statement from the post.

dtTemp: only the added rows
dt1 on end: dt1 and appended dt2 rows

2 Likes

@ppr Thanks for the solution. I will ignore the dtTemp.
Works good.

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