473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 24623
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sqlnewbie | last post by:
I'm a newbie to script writing. I'm trying to write a script to copy all data from a table to the same table in a 2nd database. Both databases are on the same server and are identical in design. ...
2
by: ja | last post by:
hi, How copy two table between two database? copy 1 table1 to 2 table2 1 - cursor number, 2 - cursor number, table1 - sourse table table2 - destination table
4
by: Robert Stearns | last post by:
For testing purposes I propose to add a schema (testing, how original) and would like to copy some of my live tables to it, both structure and data. I know I could use something like dump/restore...
0
by: Ray | last post by:
I tried to make a copy of table but received an error: The Microsoft Jet database engine stopped the process because you and another user are attempting to change the same data at the same time. ...
2
by: Marcin Zmyslowski | last post by:
Hello all! How to copy a table in MS SQL Server 2000 without chaning a structure? I mean, I have one table, which has autoincrement numeric field (ID). When I copy this table by exporting this...
4
by: realjacky | last post by:
How can i copy a table to a new table(structure and data) with primary key remain i have try to use Select * into table from old_table However, i dont have any primary key which old_table have...
6
by: sql_server_user | last post by:
I'm trying to copy all 440 million rows from one table in my SQL Server 2005 db to another table with a different clustering scheme. After a few test inserts that were successful (up to a million...
9
by: fniles | last post by:
I would like to copy a table(s) from SQL Server 2005 to a CVS file and vice versa. I was thinking to use the BCP command line utility, but I have a few questions: 1. The machine where I am...
16
mikek12004
by: mikek12004 | last post by:
How to copy a table (with the data) from one server to another (the two servers are in different PCs)? Basically if I could move the data to a txt file inthe form of the insert command (like the...
2
by: vcomp | last post by:
I have a table that includes BLOBs which are audio files. I need to copy the table to another database. Normally I just copy the records and insert them into the second table but I'm guessing I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.