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

How to make pagination more efficient

Sl1ver
196 100+
here is my sql

Expand|Select|Wrap|Line Numbers
  1. PROCEDURE [dbo].[spMobileSearch]  
  2. (
  3.     @pg            int, 
  4.     @pgSize        int,
  5.     @text        varchar(250)
  6. )
  7. AS 
  8. BEGIN
  9. Create table #temp 
  10. id int identity primary key,
  11. intTitleId int, 
  12. vcTitleName varchar(250), 
  13. intYear int, 
  14. vcCertificate varchar(250), 
  15. vcImageName varchar(250),
  16. vcTitleDescription varchar(4000), 
  17. actor varchar(4000)
  18.  
  19.  
  20. SET NOCOUNT OFF 
  21.  
  22. Insert into #temp(intTitleId, vcTitleName, intYear, vcCertificate, vcImageName, vcTitleDescription, actor) 
  23.  
  24. select * 
  25. from Titles  
  26.  
  27.  
  28. declare @from int 
  29. declare @to int 
  30. set @to=@pg * @pgSize 
  31. Set @from= @pg * @pgSize-@pgsize 
  32.  
  33. Select * from #temp where id>@from and id<=@to 
  34. Select count(*) from #temp
  35. drop table #temp 
  36. SET NOCOUNT ON 
  37. END
  38.  
dont mind the select statment, just took it out to make it look less clunky

Problem: This pager does exactly what i want it to do but struggles when it comes to a big resultset. E.g everytime you click next in the asp page, it feels like it is searching the db again and this slows the pager down a lot.
Oct 10 '11 #1
2 1884
Sl1ver
196 100+
I have found a solution to this problem and speeds up the paging supper fast

Expand|Select|Wrap|Line Numbers
  1. PROCEDURE [dbo].[spMobileSearch]  
  2. (
  3.     @pg INT,
  4.     @pgSize INT,
  5.     @text varchar(250)
  6. )
  7. AS BEGIN
  8.  
  9. WITH Search AS
  10. (select distinct ROW_NUMBER() OVER (Order by T.intTitleId) AS RowID, T.intTitleId, from tites.....)
  11.  
  12. SELECT rowid, intTitleId, vcTitleName, intYear, vcCertificate, vcImageName, vcTitleDescription, actor
  13. FROM Search WHERE RowID BETWEEN 
  14. ((@pg - 1) * @pgSize) + 1 AND @pg * @pgSize
  15. ORDER BY RowID
  16.  
  17.  
Oct 10 '11 #2
Frinavale
9,735 Expert Mod 8TB
It is searching the DataBase again.
You could use an ASP.NET control like the DataView which has paging functionality. This way you make 1 call to the database to populate the DataView and then cache the DataView into ASP.NET cache or Session (or something) so that you don't need to make more calls the database.
Oct 11 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Richard | last post by:
My employer currently pays me $1/hour when I carry a pager. I have to carry the pager every fourth week. The problem is that my employer insists that I be available when I'm carrying the pager. ...
4
by: john_20_28_2000 | last post by:
Does anyone know of anything out there that I can use to dial up a numeric pager, leave a number and then hang up? It is not a "fancy" pager. No message, not text, no nothing. Just a regular old...
2
by: Ben | last post by:
Hi, I'd like to have a datagrid that has a dropdownlist in the pager control for setting the page size. I can get the control into the pager inside the datagrid itemcreated event by checking for...
1
by: strout | last post by:
I know it's dumb ... sometimes frustrating I want the text and a dropdownlist align with both side of a table cell, i.e. text align left and dropdownlist align right. I cannot add more cells to...
0
by: James T. | last post by:
Hello! I am using following code to customize DataGrid Pager. It works fine... My question is, how I can replace"&nbsp" with " | " between each LinkButton control? Thanks! James Dim...
0
by: Ray | last post by:
I am trying to add a "Next >" and "<Prev" button to the pager of my datagrid. I have been able to add the hyperlinks to the pager. I am now trying to determine the correct postback script to...
1
by: SMichal | last post by:
Hi, I need a liitle help with build of my custom pager for gridview...I made this kind of pager..I looks like this: << < 1 2 3 4 5 6 7 8 9 10 > Well...it's no bad but I wannt something like...
2
by: =?Utf-8?B?QHdpbg==?= | last post by:
Hello There, I need to page a pager whenever an error event takes place in my app. What is the best approach in this? Should I use and modify the SerialPort class to talk to the modem. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.