Paging a SqlDataReader in C#

  • Thread starter Thread starter Jeremy Ames
  • Start date Start date
J

Jeremy Ames

Is there a way to setup paging with a data reader? For instance, I only want 10 records at a time, and I can move through the next ten when I need them. From the members that I saw listed in the MSDN library, it does not appear that there is. Can someone please help? Also, is there a way to find out the number of results that a stored procedure returns?
 
There is no paging build into the SqlDataReader. You usually bind it to a datagrid and then turn on paging for the grid by setting the AllowPaging to true and handling the PageIndexChanged event.


--
Hope this helps,
Bryant Hankins
Numinet Systems Inc.
http://www.numinet.com/blogging



Is there a way to setup paging with a data reader? For instance, I only want 10 records at a time, and I can move through the next ten when I need them. From the members that I saw listed in the MSDN library, it does not appear that there is. Can someone please help? Also, is there a way to find out the number of results that a stored procedure returns?
 
A dataReader is a forward only cursor. You can roll your own, of course, but
the whole idea of the DataReader is you are simply streaming data in until
you get to the end. It does not even know how many records until it is done.

I would switch to a DataSet and be done with it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
Is there a way to setup paging with a data reader? For instance, I only want
10 records at a time, and I can move through the next ten when I need them.
From the members that I saw listed in the MSDN library, it does not appear
that there is. Can someone please help? Also, is there a way to find out the
number of results that a stored procedure returns?
 
That worked well. I just had to teach myself how to use the dataset objects.
Thanks for your help.

in message A dataReader is a forward only cursor. You can roll your own, of course, but
the whole idea of the DataReader is you are simply streaming data in until
you get to the end. It does not even know how many records until it is done.

I would switch to a DataSet and be done with it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
Is there a way to setup paging with a data reader? For instance, I only want
10 records at a time, and I can move through the next ten when I need them.
From the members that I saw listed in the MSDN library, it does not appear
that there is. Can someone please help? Also, is there a way to find out the
number of results that a stored procedure returns?
 
Back
Top