Home All Groups Group Topic Archive Search About

Adding additional ResultSets to an IDataReader

Author
1 Mar 2006 1:42 PM
Jeff
Hello,

I am using an object oriented approach that passes a datareader object from
a parent object down to it's children. When I use this approach with MS
SqlServer I just run a stored procedure that includes 2 select statements
and use the DataReader.NextResult when I need to get to the second
resultset.

The problem is that for this project I am being forced to use a database
which does not have the capability to return multiple resultsets via one hit
to the database (Intersystems Cache database). Since I really don't want to
have to change my framework model, I am looking for alternatives. What I
have come up with as a possibility is; Create a custom DataReader object
implementing IDataReader. My custom object should have a way to add
resultsets. If I can do this, I will be able to make multiple calls to Cache
(individual selects) and call a CustomDataReader.ResultSets.Add(<new
datareader results>). That way, once it's populated I can use the datareader
just as I always have using CustomDataReader.NextResult() to get to my data.

I think I see a few different ways to do this, but I wanted opinion from
others. I could internally store a List (Of DataReader) and then have
nextresult iterate those ( remember I can only get 1 resultset back from the
db per datareader). I could get the rows back and store it internally and
iterate an internal list (read and store just the data), etc.

Suggestions are welcome!

Thanks for taking the time, sorry about the lengthy post.

Jeff

Author
1 Mar 2006 3:47 PM
Sahil Malik [MVP C#]
If you're using .NET 2.0, an easier solution may be to simply fill multiple
DataTables and work with DataTableReader instead.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------


Show quote
"Jeff" <jnoblemcsd.r.emo_ve.meforspam@hotmail.com> wrote in message
news:ObyyvXTPGHA.2696@TK2MSFTNGP14.phx.gbl...
> Hello,
>
> I am using an object oriented approach that passes a datareader object
> from a parent object down to it's children. When I use this approach with
> MS SqlServer I just run a stored procedure that includes 2 select
> statements and use the DataReader.NextResult when I need to get to the
> second resultset.
>
> The problem is that for this project I am being forced to use a database
> which does not have the capability to return multiple resultsets via one
> hit to the database (Intersystems Cache database). Since I really don't
> want to have to change my framework model, I am looking for alternatives.
> What I have come up with as a possibility is; Create a custom DataReader
> object implementing IDataReader. My custom object should have a way to add
> resultsets. If I can do this, I will be able to make multiple calls to
> Cache (individual selects) and call a CustomDataReader.ResultSets.Add(<new
> datareader results>). That way, once it's populated I can use the
> datareader just as I always have using CustomDataReader.NextResult() to
> get to my data.
>
> I think I see a few different ways to do this, but I wanted opinion from
> others. I could internally store a List (Of DataReader) and then have
> nextresult iterate those ( remember I can only get 1 resultset back from
> the db per datareader). I could get the rows back and store it internally
> and iterate an internal list (read and store just the data), etc.
>
> Suggestions are welcome!
>
> Thanks for taking the time, sorry about the lengthy post.
>
> Jeff
>
Author
1 Mar 2006 4:26 PM
Jeff
Sahil,

I am using 2.0, but it looks like a chore to setup the array of datatables
every time I want to create the reader. I think it would be easier if it
took in a dataset and read in the tables, but there doesnt look like a way
to do that.

You are correct though, it is an alternative. Thanks for the thoughts! I
didnt even know that reader existed.

Jeff

Show quote
"Sahil Malik [MVP C#]" <contactmethrumyblog@nospam.com> wrote in message
news:%23P1imdUPGHA.2816@TK2MSFTNGP15.phx.gbl...
> If you're using .NET 2.0, an easier solution may be to simply fill
> multiple DataTables and work with DataTableReader instead.
>
> - Sahil Malik [MVP]
> ADO.NET 2.0 book -
> http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
> ----------------------------------------------------------------------------
>
>
> "Jeff" <jnoblemcsd.r.emo_ve.meforspam@hotmail.com> wrote in message
> news:ObyyvXTPGHA.2696@TK2MSFTNGP14.phx.gbl...
>> Hello,
>>
>> I am using an object oriented approach that passes a datareader object
>> from a parent object down to it's children. When I use this approach with
>> MS SqlServer I just run a stored procedure that includes 2 select
>> statements and use the DataReader.NextResult when I need to get to the
>> second resultset.
>>
>> The problem is that for this project I am being forced to use a database
>> which does not have the capability to return multiple resultsets via one
>> hit to the database (Intersystems Cache database). Since I really don't
>> want to have to change my framework model, I am looking for alternatives.
>> What I have come up with as a possibility is; Create a custom DataReader
>> object implementing IDataReader. My custom object should have a way to
>> add resultsets. If I can do this, I will be able to make multiple calls
>> to Cache (individual selects) and call a
>> CustomDataReader.ResultSets.Add(<new datareader results>). That way, once
>> it's populated I can use the datareader just as I always have using
>> CustomDataReader.NextResult() to get to my data.
>>
>> I think I see a few different ways to do this, but I wanted opinion from
>> others. I could internally store a List (Of DataReader) and then have
>> nextresult iterate those ( remember I can only get 1 resultset back from
>> the db per datareader). I could get the rows back and store it internally
>> and iterate an internal list (read and store just the data), etc.
>>
>> Suggestions are welcome!
>>
>> Thanks for taking the time, sorry about the lengthy post.
>>
>> Jeff
>>
>
>

AddThis Social Bookmark Button