How to combine datasets?

  • Thread starter Thread starter Brett Romero
  • Start date Start date
B

Brett Romero

I have one dataset with columns a thru c. Then another that gets
columns a and d thru f. I need a dataset that has columns a thru f.
What is the best way to do it?

I currently have a thru c in dataset1. Then I use a datareader for set
#2 and start constructing a new dataset in the reader loop.

Thanks,
Brett
 
Brett,

Have you tried the ImportRow method on the DataRowCollection returned by
the Rows property on the Table? Or the Merge method on the DataSet?

If those don't work, what you could do is cycle through the rows in the
destination, creating an object array with a number of elements equal to the
columns in the destination dataset. Once you do that, you can get the
ItemArray property on the source row, and then copy those items to the
appropriate items in the array you created (only copying what you can,
because of the differences in size). Then, you can call the AddRow method
on the DataRowsCollection, passing the object array representing the values.

Hope this helps.
 
Thanks. That's basically what I'm doing. I was just wondering if
there was a way to avoid the looping. I'm using a data reader for the
looping.

Brett
 

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

Similar Threads


Back
Top