473,408 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

DataSet paging vs Datareader paging

I have been paging with DataSet using "DataGridPageChangedEventArgs" and i
guess it works with only Dataset because default paging requires that the
DataGrid be able to determine the number of total records in the
DataSource.This is possible with the DataSet, but not with the SqlDataReader..
So what are the best ways to apply paging to SqlDataReader....
For example how can i apply paging with the code below:-

THANKS AND ALL IDEAS WELCOME

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'If Not Page.IsPostBack Then
'DataBind()
'End If

'Create a connection string
Dim connString As String =
"server=(local);database=Northwind;integrated security=true;"
'Dim ConnectionString As String =
"server=(local);database=pubs;integrated security=true;"
'Open a connection
Dim objConnection As SqlConnection
objConnection = New SqlConnection(connString)
objConnection.Open()

'Specify the SQL string
'Dim strSQL As String = "Select ParentID,FileCategory,FileCategoryID
from treetable where ParentID =1"

Dim strSQL As String = "Select* from treetable"

Dim Str As String
'Create a command object
Dim objCommand As SqlCommand
objCommand = New SqlCommand(strSQL, objConnection)

'Get a datareader
Dim objDataReader As SqlDataReader
objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseConn ection)

'Do the DataBinding
dgResults.DataSource = objDataReader
dgResults.DataBind()

'While objDataReader.Read()
'do something
'Str = objDataReader("FileCategory")
'End While

'Close the datareader/db connection
objDataReader.Close()

End Sub

Nov 18 '05 #1
1 8912
Here is one way to do it:

How to dynamically page through a large result set in ASP.NET by using
SQL Server stored procedures in Visual C# .NET
http://support.microsoft.com/default...42&Product=asp

The approach will generally involve passing pagesize and pagenumber
parameters to a SQL procedure in order to filter the records from the
database resultset.

--
Scott
http://www.OdeToCode.com/

On Thu, 7 Oct 2004 17:29:06 -0700, "Patrick.O.Ige"
<Pa*********@discussions.microsoft.com> wrote:
I have been paging with DataSet using "DataGridPageChangedEventArgs" and i
guess it works with only Dataset because default paging requires that the
DataGrid be able to determine the number of total records in the
DataSource.This is possible with the DataSet, but not with the SqlDataReader..
So what are the best ways to apply paging to SqlDataReader....
For example how can i apply paging with the code below:-

THANKS AND ALL IDEAS WELCOME

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'If Not Page.IsPostBack Then
'DataBind()
'End If

'Create a connection string
Dim connString As String =
"server=(local);database=Northwind;integrated security=true;"
'Dim ConnectionString As String =
"server=(local);database=pubs;integrated security=true;"
'Open a connection
Dim objConnection As SqlConnection
objConnection = New SqlConnection(connString)
objConnection.Open()

'Specify the SQL string
'Dim strSQL As String = "Select ParentID,FileCategory,FileCategoryID
from treetable where ParentID =1"

Dim strSQL As String = "Select* from treetable"

Dim Str As String
'Create a command object
Dim objCommand As SqlCommand
objCommand = New SqlCommand(strSQL, objConnection)

'Get a datareader
Dim objDataReader As SqlDataReader
objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseCon nection)

'Do the DataBinding
dgResults.DataSource = objDataReader
dgResults.DataBind()

'While objDataReader.Read()
'do something
'Str = objDataReader("FileCategory")
'End While

'Close the datareader/db connection
objDataReader.Close()

End Sub


Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: srinivas | last post by:
I have a table with 1 million rows. I want to DISPLAY all the rows in ASP.NET page. If 10,000 users are accessing my page. I need to go for Datareader or Dataset...Problem is, if i use Datareader...
1
by: Al | last post by:
in order to implement sorting, paging in a datagrid, can I have the datasource of the datagrid a datareader or it must be a dataset then I create a dataview and make it a datasource of the...
1
by: Rob via .NET 247 | last post by:
Ok, I'm new to .NET so I'm afraid I'm doing something stupidhere, but I'm trying to populate a DataSet manually from aDataReader, and its turning out to be ridiculously difficult. Yes, I could use...
14
by: Bihn | last post by:
I was reading about datareader which is said to be slimmer & faster then dataset. Since the datareader have to go fetching the dat from the database every time it need it, the data it gets then...
6
by: Natan Vivo | last post by:
I had to built a custom data paging control for my asp.net app and SQL Server. This is what I'm doing: 1. do a SELECT to a SqlDataReader 2. create a DataTable with data from GetSchema() 3....
4
by: rodchar | last post by:
hey all, Regarding paging and sorting in a datagrid, is it better to: A: persist a dataset in session or B:
11
by: ^MisterJingo^ | last post by:
Hi all, I have a form with 4 dropdownlist controls which I populate with data from DB tables. I have a class with a method which constructs a dataset, putting each DB table into a dataset table....
3
by: nyhetsgrupper | last post by:
Hi everyone, In a datagrid the entire data is read but only the page you want is displayed to the user when you enable paging. Does the Gridview control works in the same way? So if you have...
2
by: jaredciagar | last post by:
Hi Guys, Please Help ME.... I have a problem in displaying data in my gridview with paging, the data from the database is displaying to my gridview but I want to allow paging in my gridview.how can...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.