How add a column from a datatable to another datatable?

I have a datatable with 1 column in and I want to add it another data table, how do I achieve this? I’m trying to use Add Column to data table but can’t seem to figure out how to add the exsiting column to the other datatable.

Regards,
Wil

Hi,

If number of rows of both dataable is same, the following will work.

Hope this helps you.

Regards,

I thought of this but is there a way where I can add the whole column without looping through rows?

@wdescalsota

If you know the last column in other excel file then write this DataTable using Write Range activity into it.

the datatable that I’m trying to transfer is always single column and I’m trying to add it to the other datatable where it leads me to having multiple columns in that datatable. I need it in the datatable not in an excel

@wdescalsota

You can use the "Add data Column " Activity for adding the column .

yup, I tried using it but all I can do is add an empty column

@wdescalsota
did not get you.

@wdescalsota
you tried to add the column having the null value.

when I try to use the add data column, it just adds a column, what I’m trying to do is add an existing column with data in it to the other data table

Hi,

without looping through rows?

What is your concern with using loops? If it’s performance, we can use InvokeCode and/or LINQ to improve it.

Regards,

Yes since the I think within the columns would sometimes be having high volumes, but is there a way without using invoke code or linq?

@wdescalsota

use linq to extract the specific column and join it with the datatable .

My apologies in advance, I’m still unfamiliar with linq, how do I achieve this?

@wdescalsota
try this :

test1.AsEnumerable.Select(Function(x) x(“Column2”))

test1 : input dt
Column2 : target column

testing, just a sec

do I use invoke code with this?

doesn’t seem to work on my end, can send a xaml sample file for this. It would really be helpful to see, Thank you

Just create one temporary excel file and do the steps as mentioned in my previous post and then read the data from Excel file and delete it. It’s simple solution as you don’t want to loop one by one row and unfamiliar with Linq and Invoke code.

Hi,

The following is one of LINQ ways. Hope this helps you.

img20220402-1

dtResult = dtResult.AsEnumerable.Select(Function(r,i) dtResult.Clone.LoadDataRow(r.ItemArray.Take(length).Concat(dt1.Rows(i).ItemArray).ToArray,False)).CopyToDataTable()

Note: this sample assumes number of rows of both datatable is same.

Sample20220401-6.zip (2.9 KB)

Regards,