TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Copy a Datacolumn from a table to another

C#(C Sharp)

 
 
Thread Tools Display Modes
Unread 01-10-2007, 08:59 AM   #1
Manuel
Guest
 
Posts: n/a
Copy a Datacolumn from a table to another

Hi to all,
I'm trying to copy a Datacolumn from a table to another, but with this code:

destTable.Columns.Add(srcTable.Column["colname"]);

I got this error:

Column 'colname' already belongs to another DataTable.

Anyone can help me?
 
Unread 01-10-2007, 03:07 PM   #2
Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
Re: Copy a Datacolumn from a table to another

Hi,

"Manuel" <vanilla.in@the.sky> wrote in message
news:qq2Mi.129448$U01.1019805@twister1.libero.it.. .
> Hi to all,
> I'm trying to copy a Datacolumn from a table to another, but with this
> code:
>
> destTable.Columns.Add(srcTable.Column["colname"]);
>
> I got this error:
>
> Column 'colname' already belongs to another DataTable.


You have to recreate the column and copy the data yourself, unfortunatelly
DataColumn does not implement a Clone method


 
Unread 01-10-2007, 05:09 PM   #3
Manuel
Guest
 
Posts: n/a
Re: Copy a Datacolumn from a table to another

Ignacio Machin ( .NET/ C# MVP ) ha scritto:
> Hi,
>
> "Manuel" <vanilla.in@the.sky> wrote in message
> news:qq2Mi.129448$U01.1019805@twister1.libero.it.. .
>> Hi to all,
>> I'm trying to copy a Datacolumn from a table to another, but with this
>> code:
>>
>> destTable.Columns.Add(srcTable.Column["colname"]);
>>
>> I got this error:
>>
>> Column 'colname' already belongs to another DataTable.

>
> You have to recreate the column and copy the data yourself, unfortunatelly
> DataColumn does not implement a Clone method
>
>

Thanks for the reply
 
Unread 03-10-2007, 04:00 AM   #4
Som Nath Shukla
Guest
 
Posts: n/a
Re: Copy a Datacolumn from a table to another

u can use this
DataTable dt1 = new DataTable();
dt1.Columns.Add("hi");
DataTable dt2 = new DataTable();

DataColumn dc = new DataColumn();
dc.ColumnName = dt1.Columns["hi"].ColumnName;
dc.DataType = dt1.Columns["hi"].DataType;

dt2.Columns.Add(dc);

here i am creating new column and seting properties of new column from
previous cloumn properties . u can set as more propery as u want. nowur new
column will same as prevoius one . now add this to new table.
u can not add single column to two different table.

"Manuel" wrote:

> Ignacio Machin ( .NET/ C# MVP ) ha scritto:
> > Hi,
> >
> > "Manuel" <vanilla.in@the.sky> wrote in message
> > news:qq2Mi.129448$U01.1019805@twister1.libero.it.. .
> >> Hi to all,
> >> I'm trying to copy a Datacolumn from a table to another, but with this
> >> code:
> >>
> >> destTable.Columns.Add(srcTable.Column["colname"]);
> >>
> >> I got this error:
> >>
> >> Column 'colname' already belongs to another DataTable.

> >
> > You have to recreate the column and copy the data yourself, unfortunatelly
> > DataColumn does not implement a Clone method
> >
> >

> Thanks for the reply
>

 
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How copy table from one doc to another? mscertified Microsoft Office 1 27-09-2007 07:01 PM
How to show copy process when I use System.IO.File.Copy function Michael VB.NET 18 26-09-2007 08:22 AM
given a copy of office 2003 found it was a pirate copy, Red6466 Microsoft Office 2 18-09-2007 05:02 PM
datacolumn DaveP C#(C Sharp) 3 16-09-2007 10:02 PM
link a table cell to another table cell in Word davo Microsoft Office 6 28-08-2007 09:00 AM


< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 08:50 PM.


vBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2013, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional