How do I add a column (with data) to an existing data Table?

Hello mates,
I have a data table with the first column as department name (eg. design dpt., finance dpt. etc). The next column contains data of company A ( say Expenses of that particular department for company A). I am iterating through data for 3 companies and I want to add expense data of companies in Columns. Constraint is that I do not want to use an excel file in this process because I need to do further operation on this data able. How can I add a column to a datatable ?

Hi

We can use add Datacolumn activity to add a new column to the right end of existing datatable

And if you want to add in the middle use set ordinal method
Pls find the below thread for referral

@choudhary.varun

Hi @Palaniyappan , Thanks for the reply. Can you please tell me how to pass column values. I have datatable and column name handy but how to pass the required data

Once after adding the column to datatable we can feed the data with a loop or with a normal assign activity
I would like to know how you have the input I mean in which type

Cheers @choudhary.varun

2 Likes

@choudhary.varun

Adding to @Palaniyappan answer

If u need to add default value , u can add in the default value section of add data column activity.

Or

Using some kind of code u can able to achieve the following as well if u need

1 Like

Use Invoke Code to add new columns to table. You can add columns with default values, also you can use some formula based on other columns data.

Source table data (dt_Table): Check the image below

Invoke code:

This line added column and added data by Concatenate 2 existing columns values
dt_Expenses.Columns.Add(“NewColumn1”,GetType(String),“Convert([Tcode],‘System.String’)+Convert([Input],‘System.String’)”)

This line added column with a default value.
dt_Expenses.Columns.Add(“NewColumn2”,GetType(Decimal), “Convert(123.5,‘System.Decimal’)”)

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.