Merge two tables of a Dataset in only one Datatable

W

Wasco

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
 
R

Remy

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
 
W

Wasco

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?
:-|
 
R

Remy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top