473,549 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataSet paging vs Datareader paging

I have been paging with DataSet using "DataGridPageCh angedEventArgs" 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.EventArg s) 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=North wind;integrated security=true;"
'Dim ConnectionStrin g As String =
"server=(local) ;database=pubs; integrated security=true;"
'Open a connection
Dim objConnection As SqlConnection
objConnection = New SqlConnection(c onnString)
objConnection.O pen()

'Specify the SQL string
'Dim strSQL As String = "Select ParentID,FileCa tegory,FileCate goryID
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(strS QL, objConnection)

'Get a datareader
Dim objDataReader As SqlDataReader
objDataReader =
objCommand.Exec uteReader(Comma ndBehavior.Clos eConnection)

'Do the DataBinding
dgResults.DataS ource = objDataReader
dgResults.DataB ind()

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

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

End Sub

Nov 18 '05 #1
1 8925
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*********@di scussions.micro soft.com> wrote:
I have been paging with DataSet using "DataGridPageCh angedEventArgs" 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.Thi s 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.EventAr gs) 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=Nort hwind;integrate d security=true;"
'Dim ConnectionStrin g As String =
"server=(local );database=pubs ;integrated security=true;"
'Open a connection
Dim objConnection As SqlConnection
objConnection = New SqlConnection(c onnString)
objConnection.O pen()

'Specify the SQL string
'Dim strSQL As String = "Select ParentID,FileCa tegory,FileCate goryID
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(strS QL, objConnection)

'Get a datareader
Dim objDataReader As SqlDataReader
objDataReader =
objCommand.Exe cuteReader(Comm andBehavior.Clo seConnection)

'Do the DataBinding
dgResults.DataS ource = objDataReader
dgResults.DataB ind()

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

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

End Sub


Nov 18 '05 #2

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

Similar topics

3
2763
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 there will be 10,000 connections to the database. If i use Dataset it occupies 10,000 memory blocks(xml format data) in my web server....Don't want...
1
3262
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 datagrid? The reason I am asking this question is because I already created a datagrid and made its datasource a datareader, yet, could not implement...
1
3121
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 a DataAdapter to more easily load the DataSet,but that would entail loading a couple of gigs worth of datainto memory at once, which is bound to be...
14
2226
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 should be up to date. However, both the IbuySpy and Duwamish samples and most, if not all, the shopping cart sample codes I've seen use dataset to...
6
4289
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. loop trough the datareader using .Read() to the point I want to start 4. add data to DataTable with max of records 5. close the data reader and...
4
1586
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
1695
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. I then return the DS and bind the tables to the relevant controls. I've been reading that DataReaders are much more efficient than DS's for...
3
2126
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 100000 records and you only want 10 records displayed on each page, does it read all 100000 and display 10, or does it only read what it needs (Read...
2
2783
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 I do that? I got an error msg that datareader does not allow paging in gridview.... because I use datareader in binding my data. How can I convert...
0
7736
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7982
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7827
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6066
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5385
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5110
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1079
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.