Can you merge a datareader in to a dataset?

  • Thread starter Thread starter Guest
  • Start date Start date
Not, or at least not with a Merge statement., b/c a DataSet is a
disconnected object, doesn't need the a DB for instance while a DataReader
is only valid in the context of an open and availalbe connection.
The closest you can get is to loop through the datareader and at each pass,
add the values of it to a new DataRow that matches the schema of a given
table in the dataset. Then at the end add the datarow to the datatable. Do
this until the reader is finished.
HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
In need of help said:
I want to merge a datareader in to a dataset - is there any way of doing
this?
 
You can add it, you just need to do it manually. You need to actually walk
through the reader to get the data out, so 'merge' isn't a natural fit b/c
the data isn't there already like it is with another dataset. Moreoever,
they are used for different scenarios so it's not the most natural fit.
There's nothing wrong with the idea and nothing bad about it in any way,
it's just that the usages are much different and MS probably didn't consider
it necessary in comparison to other enhancements. SInce you can walk the
DataTable and add rows based on teh DataReader, you can still get there and
if you wrote a class to handle it, you'd only have to do it once. To that
end, they do 'allow' the addition, they just don't provide a encapsulated
method to do it.

If you have any trouble doing it, just let me konw, I'll walk you through
doing it.
HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
In need of help said:
thanks, didn't think there was anyway, kind of strange as the dataset is a
disconnected store of data, so why not allow the addition of new data from a
connected source (i.e. a datareader)?
 
Perhaps you are not after this, since it is the obvious answer I thought of, but couldn't you fill the DataSet with the same command object that created the reader for you?
 
Back
Top