I have two datatables
datatable1
Name Place Age
X Swiz 30
Y USA 25
Z India 28
Data Table2
Animal
Lion
Tiger
Elephant
I would like to copy entire column (“Place”) along with data from Dt1 to Dt2 (dt1 and dt2 are not dependant. Just dump the data to dt2) which should have resultant as dt3
Assumption: dt1 and dt have same no.of rows
DataTable3
Animal Place
Lion Switz
Tiger USA
Elephant India
Create a new DataTable variable called datatable3 with columns “Animal” and “Place”.
Use a For Each Row activity to loop through each row in datatable1.
Inside the loop, use an Add Data Row activity to add a new row to datatable3. Set the properties of the Add Data Row activity as follows:
DataTable: datatable3
ArrayRow: {row("Animal").ToString, row("Place").ToString}This will add a new row to datatable3 with the values from the “Animal” and “Place” columns of the current row in datatable1.
After the loop is complete, datatable3 will contain the data you need.
1 use add datavolumn activity to add a new column and make sure type is same as the column youw ant to add
2. Then use assign dt2.Columns("NewColumnName").Expression = $"{dt1.TableName}.[Dt1ColumnName]"
I gave an example data tables. But the actual tables have many columns. The goal is to dump entire column to another datatable (which has a different column name) along with data in it.
Hi @bassu727
Does dt1 and dt2 contains similar columns or different columns?
My opinion is that, if it contains dt1 and dt2 contains similar column names then use “Join Data table” Activity to join the Datatable and store it in a new Datatable. If it doesn’t contain similar columns then try using “Merge Data Table” Activity.
Based on the above statement provided, we can simply use Write Range activity with Range starting from B1 with the DT1 as the Datatable, as DT2 is containing only a single column.
We could also dynamically get the Column Letter. But let us know if this works for your case and we can provide the Expression if required.
The above will give the Next Column Letter of the Excel Data, so for your case it will output B, you could then append “1” to it, so that the Range starts from the B1.