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

Home Posts Topics Members FAQ

to add column from one table to another table

2 New Member
--------------------------------------------------------------------------------

I want to select one or more columns from one typed datatable and add it to another table . how I can do this ?

Eg :-
table master
it has column masterid , mastername

now i select masterid and assign it to new comlunm.

Datacoloumn col = new DataColumn();

col = master.columns. masterid;

//upto this it is correct.

Now i want to add this column to another table.

DataTable tb = new DataTable ();

now if i add col to this table it gives error that

the col table is already belong to another datatable.

--------------------------------------------------------------------------------
Feb 27 '07 #1
1 2241
safalmittal
4 New Member
try using col.ColumnName= master.columns. masterid.Column Name; or "Caption" instead of "ColumnName "
--------------------------------------------------------------------------------

I want to select one or more columns from one typed datatable and add it to another table . how I can do this ?

Eg :-
table master
it has column masterid , mastername

now i select masterid and assign it to new comlunm.

Datacoloumn col = new DataColumn();

col = master.columns. masterid;

//upto this it is correct.

Now i want to add this column to another table.

DataTable tb = new DataTable ();

now if i add col to this table it gives error that

the col table is already belong to another datatable.

--------------------------------------------------------------------------------
Feb 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
21257
by: Bruce | last post by:
Hi, I want to change the datatype of an existing column from char to varbinary. When I run the "Alter Table" statement, I get the following error message - Disallowed implicit conversion from data type char to data type varbinary, table 'test.dbo.testalter', column 'col1'. Use the CONVERT function to run this query.
6
72621
by: DC | last post by:
Is there a way to use a column alias in an another calculation within the same query? Since I am using some long and complex logic to compute total1 and total2, I don't want to repeat the same logic to compute the ratio of those two columns. I know that I can do a nested query, but that seems too lengthy as well since I actually have many, many columns. select total1 = sum(case(long complex logic)), total2 = sum(case(another long...
9
25801
by: Don Grover | last post by:
I have a HTML table created using ASP as a web page. ie. HEADING1 HEADING2 HEADING3 etc... data 1 data2 data3 etc and so on How can I toggle hide / show the columns individually, anyone ever needed to do this and have any suggestions.
5
50645
by: Robert Stearns | last post by:
Either I missed something, or ALTER TABLE does not have this capability. Is there any way of doing it except DROPping all constraints which mention this table, EXPORTing the data, DROPping the table, reCREATEing the table without the 'NOT NULL property, reCREATEing the INDEXes, reloading the data, redefining all of DROPped constraints reCREATE the view which were marked inactive by the above.
10
6557
by: Colleyville Alan | last post by:
I am trying to turn a short and fat (63 columns) table into one that is tall and skinny (7 columns). Basically, I am trying to create a "reverse crosstab" using a looping structure in VBA along with SQL. I'd like to take the name of the column and input it into a descritor field. This isn't the table, but will serve as a better illustration than the real deal. If the table looks like this:
20
2755
by: Steve Jorgensen | last post by:
Hi all, I've just finished almost all of what has turned out to be a real bear of a project. It has to import data from a monthly spreadsheet export from another program, and convert that into normalized data. The task is made more difficult by the fact that the structure itself can vary from month to month (in well defined ways). So, I used the SQL-centric approach, taking vertical stripes at a time so that, for instance, for each...
3
4215
by: Gene Hubert | last post by:
I'm using DataTable.ImportRow to move data from one datatable to another... Dim dt, dtTarget As DataTable Dim dr As DataRow dt = DirectCast(Me.DataSource, DataTable) dtTarget = dt.Clone 'copy the data structure dtTarget.DefaultView.Sort = String.Empty 'remove the sort
5
11791
by: Tim | last post by:
Hi, I am trying to move a datacolumn in a datatable. What I have tried so far is to create a new datacolumn set it equal to the one I want to remove and then remove it, add another column and add it back again in the place I want it. tableStyle.MappingName = "DVGlobalPrices"; System.Data.DataColumn dCol = new DataColumn();
6
27265
by: Giacomo | last post by:
Hi, I've the following problem. I must delete a column DEFAULT from a table, but I must do it with a script, independently from the server where it'll be executed. Locally I've tried with: ALTER TABLE . DROP CONSTRAINT GO
4
15362
by: Chuck | last post by:
I'm setting the column with for a gridview (25+- columns) and have paging turned on. When the gridview is first displayed, the column widths are all set to the default. But after paging to another page, the widths are set as they should be. Going back to page one, the widths are still correct. Not a clue what's going on here!
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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
8503
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
7327
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
4152
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
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.