Populating a DataSet from a DataReader

  • Thread starter Rob via .NET 247
  • Start date
R

Rob via .NET 247

Ok, I'm new to .NET so I'm afraid I'm doing something stupidhere, but I'm trying to populate a DataSet manually from aDataReader, and its turning out to be ridiculously difficult.

Yes, I could use a DataAdapter to more easily load the DataSet,but that would entail loading a couple of gigs worth of datainto memory at once, which is bound to be bad. So I'm trying touse a DataReader to collect a group of rows, one row at a time,until I have a group which I can process. Then I perform mycalculations, store my results, clear the DataSet, and startcollecting from the DataReader again. But there doesn't seem tobe an easy way to get a row's worth of results from a DataReaderand insert them in a DataSet (that I can find, anyways.) I cameup with a convoluted set of actions involvingDataReader.GetSqlValues and DataRow.ItemValues, but as itdoesn't work I won't bore you with the details. (It doesn'tknow how to convert the elements of the generic object array tothe appropriate types for the DataRow.)

Anybody know how to get a row out of DataReader and into aDataSet?

- rob.
 
B

Bob Grommes

As I mentioned in the performance newsgroup there are new overloads to
DataAdapter.Fill() in CLR 2.0 that may be helpful.

However, it's possible that a DataTable is too general-purpose and
heavy-weight for what you need. Have you considered transferring each
incoming record to a strongly-typed passive container class and then perhaps
creating a collection derived from CollectionBase for those containers? Or
perhaps using an ArrayList of Hashtables? Or even a Hashtable of
Hashtables? If you need to do a lot of navigation by something other than
key value then you may actually need DataTables / DataSets -- but I'm just
probing. If all you are trying to escape is forward-only navigation, there
are other alternatives that may be easier for you to work with.

--Bob

Ok, I'm new to .NET so I'm afraid I'm doing something stupid here, but I'm
trying to populate a DataSet manually from a DataReader, and its turning out
to be ridiculously difficult.

Yes, I could use a DataAdapter to more easily load the DataSet, but that
would entail loading a couple of gigs worth of data into memory at once,
which is bound to be bad. So I'm trying to use a DataReader to collect a
group of rows, one row at a time, until I have a group which I can process.
Then I perform my calculations, store my results, clear the DataSet, and
start collecting from the DataReader again. But there doesn't seem to be an
easy way to get a row's worth of results from a DataReader and insert them
in a DataSet (that I can find, anyways.) I came up with a convoluted set of
actions involving DataReader.GetSqlValues and DataRow.ItemValues, but as it
doesn't work I won't bore you with the details. (It doesn't know how to
convert the elements of the generic object array to the appropriate types
for the DataRow.)

Anybody know how to get a row out of DataReader and into a DataSet?

- rob.
 

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

Top