Create Datatable with 3 Columns, 2 Columns from another datatable

Hello Guys,
Please advise.

I have a Datatable as shown below.
Now I want to add another column with some extra info which i will extract later.

My question is, if I create a new Datatable with 3columns how in the world do i transfer these 2 columns that are already in this one. UiPath is making me perplexed sometimes.
Should it be so complex that man cant find a proper answer for such a simple task!

image

Thank you guys for your time

Hi @Hurmet_Noka ,

Sharing my thoughts on the requirement.

I assume that you are creating new datatable with three columns by using build datatable activity. We can consider this datatable as newDT

So we already have datatable with the two columns here we can consider this as OldDT

Next use workbook write range activity assign newDT and make sure that you added headers option so it will write only headers in the excel. Now the excel ready with the headers

Use one more write range and this time uncheck add data headers and assign the sane excel file which we have used above and provide range A2 so it will write the data under A and B column.

This is the easy we can transfer the data if you want you can read the Excel and store the new data into finalDT.

I hope you will get some help from the above comments. Thanks.

1 Like

This works but its crazy that for such a simple task we need to write and read an excel.

Thank You Buddy

Hi @Hurmet_Noka
build a data table with three columns(Ex:Out_DT)
and use this syntax

Out_DT=(
From row In Input_DT
Select Out_DT.Rows.Add({row("Column1"),row("Column2")})
).CopyToDatatable

Update us whether you got a solution or not
Thanks,
Robin

1 Like

Your welcome :grin:. Yeah we can use easy methods like merge datatable with one activity but we have two different structure for two datatables. Second one have extra column. Not sure merge works. Give it a try. I hope our forum friends suggest very simple method than this. Nice connecting with you :relaxed:

Cool this one good with linq. I think you got your solution @Hurmet_Noka . I am not fond of linq please try our friend @Robinnavinraj_S solution.

1 Like

Thank You !

Best

Your welcome

There is an activity to do this much simpler:
image

This adds an empty column named AddedColumnName to the existing DT called MyOldDT.
No need to mess around with code…

2 Likes

That’s what I did haha
Thanks a lot

Super. This is fun. Looks more simpler now. :smiley:

1 Like

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