Adding Columns to a datatable


I have a workbook with 20 columns and I need to add 4 new columns at the end namely “Old Date” , “New Date” , “Match” and “Code”. The values that would go into these columns are dynamic and are stored into 4 different variables (say a,b,c and d).

I run a for each row on the datatable (say Dt) and then assign the new columns as -

new DataColumn = Dt.Columns.Add(“Old Date”, GetType (String), a)

and similarly for the other columns using variables b,c and d. I am then writing the data table into an excel. While doing that, the output column header comes as “Old Date + (the last date)” with some random long decimal numbers in all rows of that column. For the other columns, it does not even pull the data or throws a Missing Operand ‘REP’ error.

What could be the problem ? Please help.



Hey @susbasu

Why you are not using Add Data Column Activity under Datatable Category for the same?



Hello @susbasu,

Please have a look at below picture,
create variable dt and follow a picture.



I have been trying to work on this example. Please find attached the code and the input excel.

I added a new column named “Locality” and tried to add values to it based on certain conditions. However, I am getting only the first value even if I run the counter.

Can you please help me know where is it going wrong ?


Main.xaml (19.8 KB)
Test_2.xlsx (8.6 KB)


Hi @susbasu,
I have fixed you project. I have handled by Switch activity. I have attached the Project below.

File : Adding Columns to a (14.9 KB)



Thanks a lot Bala! This is great!

However, this is just an example where there are 3 rows. How can we use the variable “vComment” to add values to the column when there are 3000 rows ?



Hi @susbasu,
I have changed a code a little without using the temp datatable. I has update with the same table. so you can use this to update more rows.

File : Adding Columns to a (9.5 KB)