473,503 Members | 1,654 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 13266
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.Tables[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
1635
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...
6
12639
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: ...
0
1030
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>...
1
1536
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...
2
2094
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(...
0
1029
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: -------------------------------...
5
16697
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...
1
6125
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...
14
8640
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
7072
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...
0
7271
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,...
1
6979
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...
0
5570
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,...
1
4998
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...
0
4666
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...
0
1498
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 ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
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...

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.