Asp. NET High Performance paging

Source: Internet
Author: User
Tags rowcount

Recently to the page to die, remember the previous has been issued to modify the DW ASP pagination method, and then wrote the hand-made ASP page, now entered. NET, of course, with the stored procedures to create pure manual high-performance paging.

Why is it called high performance, and why should it be made by hand, not used. NET existing paging controls? This goes back to when I modified the DW ASP pagination, that I still do not understand the program of this thing, will only tinkering, not to talk about the performance of the problem. I was upset, then I asked my personal technical director Zhang to help me see At that time Zhang always looked at me with a dismissive look, saying: Is It worth it?

Then I hand-built ASP page, and can't go on, Zhang always throw me a bunch. NET code: study it yourself. And then lost a sentence: to do with. NET, a few words to fix, do not bother.

Later I found that the previous paging is the entire dataset read and then do the paging processing, once the data is too large, processing can be very slow, and even the server crashes. Then the previous pagination cannot scroll like a cursor, always fixed in a group, and it is impossible to achieve the effect of the current page number in the middle.

And then we'll say. NET paging control, indeed a few words can be done, but the flaw is that I found the first problem, belong to the data read out of the kind of reprocessing, no efficiency, so finally began to hand-made asp.net high-performance paging.

The first is the stored procedure, which only extracts the data I need, and automatically returns the last page if the page exceeds the total number of data:

Program code

SET ANSI_NULLS on
SET QUOTED_IDENTIFIER on
Go
--=============================================
--Author:clear
--Create date:2007-01-30
--Description: High Performance paging
--==================================== =========
Alter PROCEDURE [dbo]. [Tag_page_name_select]
--Incoming maximum number of records and current page number
@MaxPageSize int,
@PageNum int,
--set an output parameter to return the total number of records for paging list use
@Count int output  
as
BEGIN
SET NOCOUNT on;
DECLARE
--Define sort name parameters
@Name nvarchar,
--Define cursor position
@Cursor int
--First get the total number of records
Select @Coun T = count (tag_name)
from [viewdatabase0716].[ DBO]. [View_tag];
--Define where the cursor needs to start
Set @Cursor = @MaxPageSize * (@PageNum-1) +1
--If the cursor is greater than the total number of records place the cursor at the beginning of the last page
if @Cursor ; @Count
BEGIN
--If the last page is equal to the maximum number of records per record, returns the last full page of the
IF @Count% @MaxPageSize = 0
BEGIN
IF @Cur      Sor > @MaxPageSize
Set @Cursor = @Count-@MaxPageSize + 1
ELSE
    Set @Cursor = 1
End
-otherwise returns the remaining record of the last page
Else
Set @Cursor = @Count-(@Count% @MaxPageSi Ze) + 1
End
--point pointer to page start
Set rowcount @Cursor
--where the record starts
Select @Name = tag_name
FRO M [viewdatabase0716]. [dbo]. [View_tag]
Order by Tag_name;
--Set start position
SET ROWCOUNT @MaxPageSize
--Get the page record
Select *
from [viewdatabase0716].[ DBO]. [View_tag]
Where tag_name >= @Name
Order by tag_name
Set rowcount 0
End

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.