Copy Values from One column of DT1 to another column of Dt2

Hi All,

I have values in DT1 Column and I need to move to DT2 Column.
For ex : DT1 has “ID” Column with values and DT2 has “Payment” empty column, I need to fetch values from DT1 to fill DT2, how to do that, Anyone pls suggest

Assuming that both the datatables have the same number of rows
Step1 - Read both the datatables
Step2 - Use a For each loop, refering to the current index of the DT1
Step3 - Use assign activity inside the loop to assign the value from DT1 column to DT2 Column.

Hope this helps.
Happy Learning

Hi @Manii_K

You can use merge datatable it will merge data into single datatable
If possible please share expected output it will be helpful to provide solution.

You can even try writing a LINQ query for it as a different approach
DT2 = (From row in DT1
Let x = New Object(){row(“ID”)}
Select DT2.Rows.Add(x)).CopyToDataTable

Sample Output

Sample Output

Hi @Manii_K
You can use this Linq
DT2 = (From row in DT1
Let x = New Object(){row(“Item”),row(“ID”),row(“Department”)}
Select DT2.Clone.Rows.Add(x)).CopyToDataTable

1 Like

Hi, Thanks for the Reply
I Need to update the value in existing column of DT2

Sample Output

DT2 = (From row in DT1
Let x = New Object(){row(“City”), row(“ID”), row(“Department”)}
Select DT2.Rows.Add(x)).CopyToDataTable

Hi Sudeen,

I think above will add same as DT1 in DT2 , but I have Different column name in DT2

Can I get the Query for adding only the value of ID column from DT1 to Payment column of DT2

DT2 = DT2.AsEnumerable.Select(Function(x,index) DT2.Rows.Add({x(“City”).ToString,DT1.Rows(index)(“ID”).ToString,x(“Department”).ToString}).CopyToDataTable

Is this what you meant?

No, I have several columns in DT2, Image is just a sample, I need One column values From DT1 to another column with different name in DT2

Hi @Manii_K
you can use below linq in invoke code activity

DT2.AsEnumerable().ToList().ForEach(Sub(row2)
Dim matchingID = DT1.AsEnumerable().Where(Function(row1) row1(“Item”).ToString() = row2(“City”).ToString()).Select(Function(row1) row1(“ID”)).FirstOrDefault()
If matchingID IsNot Nothing Then
row2(“Payment”) = matchingID
End If
End Sub)

Please find below screenshot I hope this will solve your issue

Happy Automation!
Akash Javalekar