473,569 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merge two tables of a Dataset in only one Datatable

Hi!
Does Anibody knows how can i perform two query sql on db from c#?

Sample:
if i do

string QDAccount = "select * TABLE1;select * from TABLE2";

then i execute then and i get a DataSet with 2 tables:
ds is a dataset
ds.Tables[0] and ds.Tables[1]

How can I merge these two tables in only one to create so a unique
Datatable?

Thanks a lot

Walter

Dec 15 '05 #1
3 13270
You could merge the two tables manually by copying row by row from one
table into the other. A dataset has operations like this.
But much better approach would be to just make a union between the two
tables in the SQL statement (This requires that both resultsets are in
the same format).

select id, name, address TABLE1 UNION select id, name, address from
TABLE2

http://www.w3schools.com/sql/sql_union.asp

Cheers

Remy Blaettler
www.collaboral.com

Dec 15 '05 #2
Thanks!
I tried to use the Union statement but I noted that some fields are
not in the same format.

Then, I used the Add method of Dataset
ds.Tables[0].Rows.Add(ds.Ta bles[1].Rows[ii]);
but i get an error like this: "This row already belongs to another
table".

?!?!? If I need to add that rows in the first table why cannot I do it?
:-|

Dec 15 '05 #3
I think you have to create a row object from table[0] and then copy the
content of the row object from table[1] into that. There are copy and
clone methods as far as I remember.

Remy Blaettler
www.collaboral.com

Dec 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1641
by: ScottDizzy | last post by:
I'm trying to load an xml file into a dataset, then load the same xml file with a slight change into a second dataset, then do a merge to see what changed between datasets. DataSet xmlDataSet = new DataSet("Original"); xmlDataSet.ReadXml("C:\\temp\\a.xml"); xmlDataSet.AcceptChanges(); PrintValues(xmlDataSet, "Original");
6
12645
by: campwes | last post by:
Hey, all. I'm trying to develop a C# app that creates Word 2003 mail merge documents with an Oracle 9i database as the datasource. I used the following as an example of how I can start out: http://support.microsoft.com/default.aspx?scid=kb;EN-US;301659 The problem is that the code provided doesn't allow me to add more users to the mail...
0
1038
by: Nauman Ahmed | last post by:
Hi, I need to populate and merge DataSet to make an XML in the following format: <?xml version="1.0" standalone="yes"?> <CompanyOrders> <CompanyProfile> <CompanyID>Test</CompanyID> <CompanyName>The Company</CompanyName> </CompanyProfile>
1
1542
by: Joey Lee | last post by:
Hi, I am confused as what the DataSet Merge() function does. Currently I have two datatable which was selected from different table in mssql. Now with both different datatable. there are unique keys which determine the the relationship.
2
2101
by: muntyanu | last post by:
Hi all, I have problem when merging existing DataTable into new dataset. DataSet ds = new DataSet(); while ( done ) { // fill myCustomDataSet.MyTable with data ds.Merge( myCustomDataSet.MyTable, bPreserveChanges, MissingSchemaAction.Add ); ds.AcceptChanges(); // tried with and without this line
0
1033
by: Allen | last post by:
We converted our app from 1.1 to 2 and some code was no longer working. The case: From a non typed datatable, convert it to a typed one. How to reproduce the bug: ------------------------------- 1) Create a project. 2) Add a new Dataset (keep DataSet1). a) Add a new DataTable (Keep DataTable1) b) Add a new DataColumn (Keep DataColumn1)...
5
16700
by: Mark Chambers | last post by:
Hi there, Can anyone explain the following (very) simple scenario. 1) I make an exact copy of my "DataSet" and delete one record from a given table (in the copy) 2) I invoke "DataSet.GetChanges()" on the above copy and pass the results to "DataSet.Merge()" on the original copy 3) If I now inspect the original copy, it shows that the...
1
6150
by: joproulx | last post by:
Hello all, Here is my problem: I am trying to merge 2 datasets but I don't want to overwrite rows that are already modified in my working dataset. Example: I have one Dataset with only one DataTable in it. The DataTable has these 2 columns: Column #1: Name="Id" Type=Int32 (Primary Key)
14
8648
by: santoshkakani | last post by:
Hi friends i can any one help me merging 2 random tables into one and displaying in gridview for example table 1 Sid SName Dno and table 2 Dno Dname Daddress
0
7695
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...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7668
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...
0
7964
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...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
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...
0
3653
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...
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.