473,657 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Colum ns.Add(srcTable .Column["colname"]);

I got this error:

Column 'colname' already belongs to another DataTable.

Anyone can help me?
Oct 1 '07 #1
3 24677
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.Colum ns.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.Colu mns.Add(srcTabl e.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.Colum ns.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
11022
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. I can do this with DTS but wanted a script I could email to a user to run in Query Analyzer. Example: Copy entire table called 'Customers' in the 'Data01' database to table 'Customers' in the 'Data02' database I want to overwrite all data...
2
1281
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
38865
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 for the data and Quest's (BTW this a very nice product) 'create like' function. That would work, but it seems a lot of work for something DB2 should know how to do.
0
1009
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. It was ok and am at loss what is wrong this time. Can someone advise the possible cause and fix. Thanks, Ray
2
2467
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 table into the same database folder I loose the specification of the field ID. Now it is not autoincrement field but usual int field. Is it possible to copy this table without changing data and structure of a table? Kindest regards
4
1451
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 could anyone help me thx
6
4172
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 rows in 20 seconds with no problem), I crossed my fingers and went whole-hog with the naive "insert into dest_table (column1, column2, ...) select column1, column2, ... from source_table" but of course it ran out of space in *both* the db log file...
9
15139
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 going to run BCP utility does not have SQL Server installed, so BCP.exe and its underlying DLLs are not there. I copied BCP.EXE, then it tells me that it expects sqlncli.dll. After I copied that DLL, it now says "Unable to load BCP resource DLL. BCP...
16
22997
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 import/export of phpmyadmin) all would be ok
2
5749
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 can't do that with a BLOB. Any suggestions on how to accomplish this task? Thanks, Vic
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.