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