Copy DataColumn Between Tables?

  • Thread starter Thread starter localhost
  • Start date Start date
L

localhost

Is it possible to copy a DataColumn from one DataTable to another? I
have a column with custom caption, default value, and Extended
Properties, and don't want to re-create the whole thing for a
DataTable in a different DataSet.

Help?

Thanks.
 
Yes you should be able to copy column. I assume you are after something like
this.

DataTable dt1 = new DataTable();
DataColumn column1 = new DataColumn("First Column");
dt1.Columns.Add(column1);

DataTable dt2 = new DataTable();
dt2.Columns.Add(dt1.Columns[0]);


Regards,

Deepak
[I Code, therefore I am]
 
Does that mean dt2 has a complete copy (column passed by value), or
only a reference to the column in dt1?

Thanks.



Yes you should be able to copy column. I assume you are after something like
this.

DataTable dt1 = new DataTable();
DataColumn column1 = new DataColumn("First Column");
dt1.Columns.Add(column1);

DataTable dt2 = new DataTable();
dt2.Columns.Add(dt1.Columns[0]);


Regards,

Deepak
[I Code, therefore I am]


localhost said:
Is it possible to copy a DataColumn from one DataTable to another? I
have a column with custom caption, default value, and Extended
Properties, and don't want to re-create the whole thing for a
DataTable in a different DataSet.

Help?

Thanks.
 
My sincere apologies. You cannot actually copy a column from one table to
another.
Once again I apologise for the incorrect information, I don't know what I
was thinking.

--
Regards,

Deepak
http://deepakaus.blogspot.com

localhost said:
Does that mean dt2 has a complete copy (column passed by value), or
only a reference to the column in dt1?

Thanks.



Yes you should be able to copy column. I assume you are after something
like
this.

DataTable dt1 = new DataTable();
DataColumn column1 = new DataColumn("First Column");
dt1.Columns.Add(column1);

DataTable dt2 = new DataTable();
dt2.Columns.Add(dt1.Columns[0]);


Regards,

Deepak
[I Code, therefore I am]


localhost said:
Is it possible to copy a DataColumn from one DataTable to another? I
have a column with custom caption, default value, and Extended
Properties, and don't want to re-create the whole thing for a
DataTable in a different DataSet.

Help?

Thanks.
 
Back
Top