Paging a SqlDataReader in C#

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?
 
B

Bryant Hankins

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?
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

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?
 
J

Jeremy Ames

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?
 

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

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top