Should I use a datareader?

D

David Beaven

I am creating an aspx page to show (i.e. read only) hundreds or probably
thousands of items from two database queries. The user may of course only
want to read one or two pages worth. I have (I think) two possible
solutions:
a) Create a dataset from a first query. Populate one new field using a
datareader (I want to concatenate each result of a second query). Pros:
Easy to navigate (e.g via datagrid), cons: memory intensive (we may only
read one page!)
b) Do both queries using a datareader. Mark my place in the query result
with a
session level variable and if wanting to show record 210-230 use the
datareader to spin
210 times before showing data. Pros: ?quicker (or can the select statement
return from row 210 onwards?), cons: need to keep track of which page /query
results are wanted.

Any suggestions greatfully received
Thanks, David
 
C

Cor

Hi David,

Why not more datasets selecting that what you need on a page?

Just a thought

Cor
 
O

One Handed Man [ OHM ]

DataReaders are a forward only reading stream of data. They are supposed to
be inherently faster that using a DataAdapter, but less flexible of course.

Having said that, if you are returning relatively small sets of data in any
one go, then you probably will not notice a vast difference between then two
unless you have a ridiculous number of columns in each row and want to
return all fields per row.

There is quite a lot you can do with your select statement to define the
number of rows returned, you could use your primary key to determine the
last point and first point in a returned set.

Depending on how you intend your UI to work , you will need to simply test a
couple of methods to see which is more efficient and then try and scale this
up in terms of number of users, (Server) machine performance and also what
operations you intend to do with the data.

I think really that there are no right and wrong answers, they are dependent
on what you are trying to acheive and a balancing act between usability,
performance and system integrety.

Regards - OHM



David said:
I am creating an aspx page to show (i.e. read only) hundreds or
probably thousands of items from two database queries. The user may
of course only want to read one or two pages worth. I have (I think)
two possible solutions:
a) Create a dataset from a first query. Populate one new field using
a datareader (I want to concatenate each result of a second query).
Pros: Easy to navigate (e.g via datagrid), cons: memory intensive (we
may only read one page!)
b) Do both queries using a datareader. Mark my place in the query
result with a
session level variable and if wanting to show record 210-230 use the
datareader to spin
210 times before showing data. Pros: ?quicker (or can the select
statement return from row 210 onwards?), cons: need to keep track of
which page /query results are wanted.

Any suggestions greatfully received
Thanks, David

Best Regards - OHMBest Regards - OHM (e-mail address removed)
 

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