copying the column values of a Datatable into another data table in vb.net

B

Balu

Hi All,

Can anybody tell me how to copy one column of a data table to another data
table.

Example:I have 2 data tables say dt1,dt2.
Here,i wanna copy only the 1st column values of dt1 into the 1st column of
dt2.
Its an urgent work for me.So,anyone of you can give me a solution to this.

Regards,
Mahalakshmi.
 
C

Cindy Winegarden

Hi Mahalakshmi,

Does the Copy() method that Christopher Reed suggested in your other thread
work for you?
 
B

Balu

Hi,
Its working fine.But,i wanna copy only one column of a table not the
entire data.
But,the statement .....
tblTwo=tblOne.Copy()
copies the entire data,i.e.,all column values into another table.
Can anybody give a solution for it?

Regards,
Maha.
 
C

Cindy Winegarden

Hi Balu,

Are you saying that you want to add a new column to a table and populate it
or populate a column that's already there but is empty? To do that you'll
need to use an update statement and connect the record in the source table
to the record in the target table via a primary key. It's not as easy as
copying/pasting a column in Excel, for example.

In a SQL Server script this would be something like:

Alter Table Target Add NewColumn Integer
Go
Update Target
Set Target.NewColumn =
(Select Source.OldColumn From Source
Where Source.PrimaryKey = Target.PrimaryKey)
 
B

Balu

Hi Cindy,
Thanks for ur reply.
But,actually what i want is, to copy a single column of the data table say
'dt1' to a column in another data table say 'dt2'.
I am using dt2=dt1.
But,its copying the entire data of data table 'dt1' to data table 'dt2'.
What i want is to copy only the 1st column data of dt1 to 1st column of dt2.
If you have any idea?Please do reply....waiting for ur reply.

Regards,
Maha.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top