Merge two tables of a Dataset in only one Datatable

  • Thread starter Thread starter Wasco
  • Start date Start date
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
 
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
 
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?
:-|
 
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
 
Back
Top