Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > copying the column values of a Datatable into another data table in vb.net

Reply
Thread Tools

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

 
 
Balu
Guest
Posts: n/a
 
      01-02-2006
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.


 
Reply With Quote
 
 
 
 
Cindy Winegarden
Guest
Posts: n/a
 
      01-02-2006
Hi Mahalakshmi,

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

> tblTwo = tblOne.Copy();


--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
http://www.velocityreviews.com/forums/(E-Mail Removed) www.cindywinegarden.com


"Balu" <(E-Mail Removed)> wrote in message
news:OuE1%(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
 
 
 
Balu
Guest
Posts: n/a
 
      01-03-2006
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.
"Cindy Winegarden" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Mahalakshmi,
>
> Does the Copy() method that Christopher Reed suggested in your other
> thread work for you?
>
>> tblTwo = tblOne.Copy();

>
> --
> Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
> (E-Mail Removed) www.cindywinegarden.com
>
>
> "Balu" <(E-Mail Removed)> wrote in message
> news:OuE1%(E-Mail Removed)...
>> 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.
>>

>
>



 
Reply With Quote
 
Cindy Winegarden
Guest
Posts: n/a
 
      01-04-2006
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)

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
(E-Mail Removed) www.cindywinegarden.com


"Balu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
> "Cindy Winegarden" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi Mahalakshmi,
>>
>> Does the Copy() method that Christopher Reed suggested in your other
>> thread work for you?
>>
>>> tblTwo = tblOne.Copy();

>>
>> --
>> Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
>> (E-Mail Removed) www.cindywinegarden.com
>>
>>
>> "Balu" <(E-Mail Removed)> wrote in message
>> news:OuE1%(E-Mail Removed)...
>>> 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.
>>>

>>
>>

>
>



 
Reply With Quote
 
Balu
Guest
Posts: n/a
 
      01-06-2006
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.
"Cindy Winegarden" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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)
>
> --
> Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
> (E-Mail Removed) www.cindywinegarden.com
>
>
> "Balu" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.
>> "Cindy Winegarden" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi Mahalakshmi,
>>>
>>> Does the Copy() method that Christopher Reed suggested in your other
>>> thread work for you?
>>>
>>>> tblTwo = tblOne.Copy();
>>>
>>> --
>>> Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
>>> (E-Mail Removed) www.cindywinegarden.com
>>>
>>>
>>> "Balu" <(E-Mail Removed)> wrote in message
>>> news:OuE1%(E-Mail Removed)...
>>>> 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.
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Cindy Winegarden
Guest
Posts: n/a
 
      01-06-2006
As I posted above, that's exactly what the code I posted above does.

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
(E-Mail Removed) www.cindywinegarden.com


"Balu" <(E-Mail Removed)> wrote in message
news:O6$(E-Mail Removed)...
> ... copy a single column of the data table say 'dt1' to a column in
> another data table say 'dt2'.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I add a row from a typed datatable to another instance of that typed datatable? Ersin Gençtürk ASP .Net 1 10-06-2004 01:11 PM
Create a Datatable from a SQL datatable column shema? jg ASP .Net 1 08-17-2004 09:43 PM
Activa or not activate a button column depending if another data column has data or not carlos perez ASP .Net 0 06-08-2004 02:16 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N ASP .Net 2 10-31-2003 01:05 PM
Adding DataTable Rows To another DataTable J. Babe ASP .Net 1 08-15-2003 05:04 PM



Advertisments