By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Copy a Datacolumn from a table to another

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.