469,346 Members | 6,562 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,346 developers. It's quick & easy.

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?
Oct 1 '07 #1
3 23660
Hi,

"Manuel" <va********@the.skywrote in message
news:qq**********************@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
Oct 1 '07 #2
Ignacio Machin ( .NET/ C# MVP ) ha scritto:
Hi,

"Manuel" <va********@the.skywrote in message
news:qq**********************@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
Oct 1 '07 #3
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" <va********@the.skywrote in message
news:qq**********************@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
Oct 3 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sqlnewbie | last post: by
2 posts views Thread by ja | last post: by
2 posts views Thread by Marcin Zmyslowski | last post: by
6 posts views Thread by sql_server_user | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.