Copying columns between Data Tables

Hi Friends,
I need your help. How can we copy a particular column from one data table to another data table?

For Example:
Let’s assume that we have 2 data tables with names DT1 and DT2. I have to copy a column with the name say “Location” from DT1 to the column by the name “Area” in DT2. Can anyone help me with the same.

regards,
Ananthu

Hi @Ananthu,

You can use for each row activity to update the value in the another datatable.

In DT2 you have only one column-Area?

Regards,
Arivu

2 Likes

Hi @arivu96,
Nope ! That’s the one leading to this confusion. I have multiple columns in DT2 as well. So, is there any option to copy one specific column from DT1 to another specific column in Dt2.

Thanks & Regards,
Ananthu

HI @Ananthu,

you can get the particular column alone to another data table using below code.

Dt2=Dt1.DefaultView.ToTable(False,"Location")

so you can move the particular column alone in another data table.

if suppose Dt2 already having some data you need add newly use for each data row to update the area column values.

Regards,
Arivu

2 Likes

Hi @arivu96,
So, you’re asking me to copy that particular column in DT 1 to a new data table. Later, copy that new data table to that particular column in DT2 right?

I thought of the same thing. I will try that and will let you know.

Is there any other simple solution ? :wink:

Thanks & Regards,
Ananthu

how to copy particular column of data to another datatable of particular column name?

Using Linq query?