473,405 Members | 2,421 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,405 software developers and data experts.

How to use SQL Server paging

I heard in an online video by Scott Gu, that there is an option to have the
asp.net datagrid in .net 2.0 do the paging in SQL Server 2005 rather than
pull all the data from the database and do it on the web server.
I've been unable to find any good documentation on this. I saw a property
to turn on paging if the select supports it, but that did not give me enough
information to complete my task.
Does anyone know where I can find documentation how to do this?

Thanks in advance,
Donald Adams
Jun 5 '07 #1
8 1431
re:
!I've been unable to find any good documentation on this.

I googled for : ( "SQL Server 2005" paging "Scott Guthrie" )
....and came up with the article in 5 seconds.

http://weblogs.asp.net/scottgu/archi...01/434314.aspx

Scott provides sample code to experiment with.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espanol : http://asp.net.do/foros/
======================================
"Donald Adams" <BD******@hotmail.comwrote in message
news:55**********************************@microsof t.com...
>I heard in an online video by Scott Gu, that there is an option to have the asp.net datagrid in
.net 2.0 do the paging in SQL Server 2005 rather than pull all the data from the database and do it
on the web server.
I've been unable to find any good documentation on this. I saw a property to turn on paging if
the select supports it, but that did not give me enough information to complete my task.
Does anyone know where I can find documentation how to do this?

Thanks in advance,
Donald Adams



Jun 5 '07 #2
This works ok only on small sets (like 100000 records or around)

Problem is this approach requires order by clause, which is very inefficient
on big tables (>1Mio records)

I have 2.5Mio records table, and selection of page in 1Mio range takes
around 30 seconds on my PC. In beginning (1st, 2nd etc pages) selection
takes 10-15 seconds. Even though I have index on table. If order by is same
as index, selection is a bit faster, but just a bit (maybe 30% in best case)

I wonder if it is possible to use row_number without order by to speed up
selection. I have index already, so SQL Server should use it by default I
think.

Alex

"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:uJ*************@TK2MSFTNGP05.phx.gbl...
re:
!I've been unable to find any good documentation on this.

I googled for : ( "SQL Server 2005" paging "Scott Guthrie" )
...and came up with the article in 5 seconds.

http://weblogs.asp.net/scottgu/archi...01/434314.aspx

Scott provides sample code to experiment with.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espanol : http://asp.net.do/foros/
======================================
"Donald Adams" <BD******@hotmail.comwrote in message
news:55**********************************@microsof t.com...
>>I heard in an online video by Scott Gu, that there is an option to have
the asp.net datagrid in
.net 2.0 do the paging in SQL Server 2005 rather than pull all the data
from the database and do it
on the web server.
I've been unable to find any good documentation on this. I saw a
property to turn on paging if
the select supports it, but that did not give me enough information to
complete my task.
Does anyone know where I can find documentation how to do this?

Thanks in advance,
Donald Adams



Jun 5 '07 #3
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:uJ*************@TK2MSFTNGP05.phx.gbl...
!I've been unable to find any good documentation on this.

I googled for : ( "SQL Server 2005" paging "Scott Guthrie" )
...and came up with the article in 5 seconds.
That's just showing off...! ;-)
--
http://www.markrae.net

Jun 5 '07 #4
re:
!That's just showing off...! ;-)

To quote the *first* recommendation in my ASP.NET FAQ :

---000---
With that in mind, the first FAQ recommendation is that you use search engines to
find out if the question you intend to ask has been already answered in newsgroups.

Use resources like : Google Groups Advanced Search and MSN Search to search for the text of
the problem which is stumping you, and save everybody the waste of time that asking a FAQ entails.

Remember : thousands of programmers will read your post. Be considerate of their time.
---000---

In this case, it wasn't a FAQ ( in fact, it was, rather pointedly, a *non-FAQ* ), but searching
Google and/or MSN *first* should be a pre-requisite to posting *any* question here.

:-)

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:%2***************@TK2MSFTNGP06.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:uJ*************@TK2MSFTNGP05.phx.gbl...
>!I've been unable to find any good documentation on this.

I googled for : ( "SQL Server 2005" paging "Scott Guthrie" )
...and came up with the article in 5 seconds.

That's just showing off...! ;-)
--
http://www.markrae.net


Jun 5 '07 #5
Putting more than 100,000 records in a grid is never going to be efficicient,
whether you have paging turned on or not. I'd revisit your design. I doubt
your user's are really going to want to look at more than a 100,000 records
in a session. I suggest changing your query to only bring back a subset of
your data and if the record the user wants isn't there, go get another chunk
of data, etc.
--
Jim Anderson, MCSD
Consultant
Columbus, Ohio
"AlexS" wrote:
This works ok only on small sets (like 100000 records or around)

Problem is this approach requires order by clause, which is very inefficient
on big tables (>1Mio records)

I have 2.5Mio records table, and selection of page in 1Mio range takes
around 30 seconds on my PC. In beginning (1st, 2nd etc pages) selection
takes 10-15 seconds. Even though I have index on table. If order by is same
as index, selection is a bit faster, but just a bit (maybe 30% in best case)

I wonder if it is possible to use row_number without order by to speed up
selection. I have index already, so SQL Server should use it by default I
think.

Alex

"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:uJ*************@TK2MSFTNGP05.phx.gbl...
re:
!I've been unable to find any good documentation on this.

I googled for : ( "SQL Server 2005" paging "Scott Guthrie" )
...and came up with the article in 5 seconds.

http://weblogs.asp.net/scottgu/archi...01/434314.aspx

Scott provides sample code to experiment with.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espanol : http://asp.net.do/foros/
======================================
"Donald Adams" <BD******@hotmail.comwrote in message
news:55**********************************@microsof t.com...
>I heard in an online video by Scott Gu, that there is an option to have
the asp.net datagrid in
.net 2.0 do the paging in SQL Server 2005 rather than pull all the data
from the database and do it
on the web server.
I've been unable to find any good documentation on this. I saw a
property to turn on paging if
the select supports it, but that did not give me enough information to
complete my task.
Does anyone know where I can find documentation how to do this?

Thanks in advance,
Donald Adams




Jun 5 '07 #6
Yes, and I might add that the ASP.NET Quickstarts should be added as a third
option. I've been doing this stuff since 2000, and I still refer to it.
Cheers,
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Juan T. Llibre" wrote:
re:
!That's just showing off...! ;-)

To quote the *first* recommendation in my ASP.NET FAQ :

---000---
With that in mind, the first FAQ recommendation is that you use search engines to
find out if the question you intend to ask has been already answered in newsgroups.

Use resources like : Google Groups Advanced Search and MSN Search to search for the text of
the problem which is stumping you, and save everybody the waste of time that asking a FAQ entails.

Remember : thousands of programmers will read your post. Be considerate of their time.
---000---

In this case, it wasn't a FAQ ( in fact, it was, rather pointedly, a *non-FAQ* ), but searching
Google and/or MSN *first* should be a pre-requisite to posting *any* question here.

:-)

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:%2***************@TK2MSFTNGP06.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:uJ*************@TK2MSFTNGP05.phx.gbl...
!I've been unable to find any good documentation on this.

I googled for : ( "SQL Server 2005" paging "Scott Guthrie" )
...and came up with the article in 5 seconds.
That's just showing off...! ;-)
--
http://www.markrae.net

Jun 6 '07 #7
On Jun 5, 7:22 pm, Jim Anderson <anderson_jim at Excite DotComwrote:
Putting more than 100,000 records in a grid is never going to be efficicient,
whether you have paging turned on or not. I'd revisit your design. I doubt
your user's are really going to want to look at more than a 100,000 records
in a session. I suggest changing your query to only bring back a subset of
your data and if the record the user wants isn't there, go get another chunk
of data, etc.
--
Jim Anderson, MCSD
Consultant
Columbus, Ohio
I fully agree with Jim.

Anyway, there are some things that you can check, Alex.

1) Index for the ORDER BY field. Update statistics for the table

2) For the first N pages you could do the following query

SELECT * FROM (SELECT TOP 110 ROW_NUMBER()
OVER (order by id) AS RowId, * FROM Table1) a
WHERE RowId 100 AND RowId <= 110

In this example I select 10 rows starting from 101 through 110 (page
#10)

This should be faster on the large tables

3) and finally

http://www.4guysfromrolla.com/webtech/042606-1.shtml

Hope it helps

Jun 6 '07 #8
On Jun 6, 2:22 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
SELECT * FROM (SELECT TOP 110 ROW_NUMBER()
OVER (order by id) AS RowId, * FROM Table1) a
WHERE RowId 100 AND RowId <= 110
Also do not use SELECT * FROM :-)

Specify only the fields you need.

Jun 6 '07 #9

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

Similar topics

1
by: Christopher Pragash | last post by:
Hello All I am having a pretty wired problem...I am writing a web part (SPS 2003) that uses a Datagrid. In the web part, I create the datagird assign some properties and add event handlers for...
2
by: Rathtap | last post by:
I am displaying data in a bound datagrid. Is there a way to provide paging through client-side script? That is, without re-loading the page. I am willing to have the initial overhead of bringing in...
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: Manuel Alves | last post by:
Scenario: ASP 2.0 on XP pro dev machine works fine. Publishing to windows 2003 server worked OK until I included paging for a datagrid. On page load I cal sub binddata Private Sub...
17
by: IanIpp | last post by:
We have a 3 month old quad processor/dual core server running SQL Server 2005 and already it is getting close to hitting the CPU wall. An 8 way CPU box is prohibitively expensive and out of the...
1
by: mrcraze | last post by:
Hi Everyone! We are using a cursor for paging results in SQL server, mainly due to the performance gains achieved when working with large results sets. We have found this to be of great benefit...
1
by: rbg | last post by:
I am using derived tables to Page data on the SQL Server side. I used this link as my mentor for doing paging on the SQL Serverhttp://msdn2.microsoft.com/en-us/library/ms979197.aspx I wanted to...
8
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table,...
2
by: Ilyas | last post by:
Hi all I need to implmenet paging across different tables. The tables all have a different name eg Data01, data02 data03 etc, however they are columns which are common to each table, but each...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.