Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append one datatable to another? 1

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
US
Hi Folks

I have two datasets from separate queries. The two tables have the same structure, what I want to do is combine them into one table which I can then assign to a grid control.

How can I do this? Either appending one into the other is fine, or both into a third table is fine.

Thanks!

CraigHartz


CraigHartz
 

Hey Craig

I've always done it row by row, something like this (untested):

Code:
[green]' copy all rows from table(1) into table(0)[/green]
Dim iCnt As Integer
Dim dr As DataRow

  With ds.Tables(1)
    For iCnt = 0 To .Rows.Count - 1
      dr = .NewRow
      dr = .Rows(iCnt).ItemArray.Clone
      ds.Tables(0).Rows.Add(dr)
    Next
  End With
End Sub

If anybody knows an easier or more efficient way of doing it I'd like to find out about it.

Pat
 
If the 2 datasets are identical, you should be able to do:

Code:
ds1.Merge(ds2)

This should add the rows of "ds2" to "ds1".

Hope this helps!

--Rob
 

Rob,

Do the tables have to be in the same dataset or will that work on standalone tables too?

Thanks,
Pat
 
Thanks Rob, that did the trick! A nice, simple solution. I'll write that one down!

CraigHartz


CraigHartz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top