Paging with datareaders

  • Thread starter Thread starter Mike Smith
  • Start date Start date
M

Mike Smith

Hey people,

When a datareader is used for paginh with a datagrid in asp.net, we have to
use the custom paging method ?

How do we find out the total records returned from the datareader itself ?

Any samples of using the grid with datareaders to achieve efficient paging ?
Efficient here meaning it fetches only 10 records each time a page is
requested and not all the records at one time.

Regards,
Mike.
 
You can't find the total number of records without iterating through the
datareader. in 2003 you can use the .HasRows to know if you have anything,
but that's about it.

Also, since the DataReader doesn't implement IEnumerable, I don't think you
can page with it....Even if you can, I doubt you'd want to b/c the
DataReader can only do things for you while it's connected to the db. If
you are going to page with it, that's a long time to hold a connection open.

If you need paging and sorting, I'd recommend using a Datatable, build a
view based on teh DataTable and bind to the view. You can do a whole lot
with it very easily.

HTH,

Bill
 
geez so much for using datareaders for efficiency...
its pretty tricky with it.. one has to fetch the first 10 records and keep
track each time.. how about if i got no autonumber to base on how should i
know whats my reference especially if its already sorted on different fields
! argh !
i rather go the inefficient way then... datasets here i come !
 
Faster and efficient aren't always the same thing. Nor useful.....An F-16
is much faster than my bike, but it doesn't do me much good if I need to get
to the gym. DataReaders are great for many things...but no things that need
traversal in multiple directions.

If you need to move around in the record set, a DataTable is probably the
way to go.
 
Back
Top