Add column with its data to another data table

Assuming below is the column that I filtered (dt2). I want to add this filtered column to another data table

Amount
1896.923289
1102414.908174
714.178
1851.649981
10103.52375
22300.8302

Another table value (dt1) is as below

Destination,Rate,Mins
China,0.017,110286.25
India,0.23,4850043.58333333
Korea,0.015,47611.8666666666
MALAYSIA,0.2,9258.25
Singapore,0.009,1122613.75
Yemen,0.21,104698.733333333

I tried to use Add data column, but it gives me error “Add Data Column: Column ‘Amount’ already belongs to another DataTable.”. The properties as below;

Column: dt2.Columns(“Amount”)
DataTable: dt1

You can refer to this solution.

Hi

If this is in a datatable named dt2 then the below steps will help you resolve this

—use a assign activity and mention line this

dt_col = dt2.Columns(0)

Where dt_col is a variable of type System.Data.DataColumn defined in variable panel

—now use ADD DATACOLUMN activity and pass the above variable to DataCol property and in datatable property mention as dt1

Cheers @aqiff

. Nope still give me an error “Amount” belongs to another datatable.

i’ve tried this, but it gives me a column of data table with empty values

Can you share your workflow or screenshots of activities + properties please?

@aqiff

Can you share the excel files if you have and also check the output you required

Thanks

Before to this step use a assign activity and give a try by changing the columnname

dt2.Columns(0).ColumnName = “Amounts”

We are just trying add like Amounts instead of amount

And then use this in a assign
dt_col = dt2.Columns(0)
Then continue further with the above mentioned steps

Cheers @aqiff

@Palaniyappan @Charbel1 @Srini84 , Attached is the workflow. Sorry for the late reply, inside the workflow, Method 1 is by @Charbel1 , Method 2 is by @Palaniyappan . Both has its own error. Do try it out

SortRate2.xaml (14.9 KB)

I’m not getting any error from my side for Method 1. I runned your workflow on my machine.

Can you please send the error that you are getting?

If you in debug mode, The column for “Amount” is empty

Yeah, you’re right just checked it…

Did you try a simple for each row maybe?

I’ve used this, but I thought, maybe there is much more easier and convenient way to add new data column.

After some search, the reason we can’t do this is that the reference of the column is tight to its Datatable which means that if you add this column to another Datatable, you will mess the references which can blow your program.

That’s why the only method would be to copy the data one by one (For Each Row).

But the first answer is still valid to add the column name and the type (but without data, unfortunately…)

Best,
Charbel

Hi

This steps should be working

Pls upgrade the UiPath.System.Activities package and UiPath.UIAutomation package and give a try

Cheers @aqiff

I have upgraded and nope, its not working