ASP unlimited stream paging code or instance

Source: Internet
Author: User
<%
'**【 Program Function]
'**
'** It performs paging operations on large databases, and the ideal number of operable data records is 2 million.
'** Or less (max level edition has no limit on the number of pages, regardless of the database size.
'** Unchanged). This is the paging program of the million level edition in the race Yang 1g, memory 512, Win2k ring.
'** Test data:
'**
'** Sqlserver 2 K + 0.1 million records + 20 records per page:
*** Average page turning speed: 45 Ms
'** Sqlserver 2 k + 1 million records + 20 records per page:
*** Average page turning speed: 350 ms
'**
'**
'** [Paging principle]
'**
'** This program no longer uses the Rs. pagesize Method for paging. the type of the cursor connecting to the database
'** Does not use Conn, 1, x, but Conn,. This should be the fastest cursor type.
'** Think this will complicate the program. On the contrary, the program is very simple. If you cannot understand it,
'** It should be my programming style that you are not used to, rather than complicated programs.
The center of the '** "infinite stream" page is that only the records to be displayed are read on each page.
'** The paging program prereads all the data, which is the biggest advantage of this program-less resources, the same
'** The processing speed has also been greatly improved, especially when the data volume is large, its speed advantage
'** The more obvious (1 million records are about ms ).
'** When the program is executed, use curcorbegin and curcorend to record the first entry
*** The id value of the record and the last record as the marker for the next page flip, and then use top XX to obtain
'** Displays the required data and records the id value.
'**
'** [Statement]
'**
'** This program is a shared version and is provided to programmers for research and use.
*** For modifying or other purposes, please respect the author's hard work and indicate the source.
'** If this program has defects such as errors and omissions or non-optimization, please go to the webdevelopment at http://www.csdn.net/
'** The ASP topic is discussed. Please do not stick to it for the sake of the development of the Chinese Software Industry :)
'**
'*************************************** *****************************

Option explicit
'Response. Flush
Dim begintime, endtime
Begintime = Timer
Dim Conn, sqlstr, RS, defrecordnum, cursorbegin, cursorend, curpagenum, hav
Defrecordnum = 20

'-------------- Get the relevant parameter ----------
If request ("cursorbegin") = "" Then cursorbegin = 0 else cursorbegin = request ("cursorbegin ")
If request ("cursorend") = "" Then cursorend = 0 else cursorend = request ("cursorend ")
If request ("curpagenum") <> "" then
Curpagenum = clng (Request ("curpagenum "))
If curpagenum <= 0 then curpagenum = 1
Else
Curpagenum = 1
End if
Hav = request ("hav ")
If hav = "" Then hav = "Next"
'---------------- End -----------------

'------------ function for displaying paging content --------
function turnpagefs (disprecordnum)
dim N
while not (RS. EOF) and n N = n + 1
response. write "" & _
"" & RS (0) & "" & _
"" & RS (1) & "" & _
"" & RS (2) & "" & _
"" & RS (3) & "" & _
"" & RS (4) & "" & _
"" & RS (5) & "" & _
""
if n = 1 then cursorbegin = RS (0)
if n = defrecordnum or Rs. EOF then cursorend = RS (0)
Rs. movenext
Wend
end function

'------------- Connect to the database -------------
Set conn = server. Createobject ("ADODB. Connection ")
'Sqlstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath ("mldata. mdb ")
Sqlstr = "driver = {sqlserver}; server = arbiter; uid = arbiter; Pwd = 123456; database = mldata"
Conn. Open sqlstr

'--------- Total number of records/total number of pages ---------
'-PS: Count (ID) is recommended. The ID is automatically numbered and indexed. Otherwise, the speed may be compromised.
'-PS: This is the most resource-consuming part of the program. If this program is canceled, the speed will be about 10 times faster.
Dim totalrecords, totalpages
Sqlstr = "select count (ID) as recordsum from ABC"
Set rs = conn. Execute (sqlstr, 0, 1)
Totalrecords = RS ("recordsum ")
Totalpages = ABS (INT (totalrecords/defrecordnum * (-1 )))
Rs. Close
Set rs = nothing

'-------- Select the corresponding SQL string according to hav -----
Select case (HAV)
Case "back"
Cursorend = cursorbegin
Sqlstr = "select top" & defrecordnum & "ID, title, filename, K, imgsize, nameson from ABC where ID <" & cursorbegin &_
"And ID in (select top" & defrecordnum & "id from ABC where ID <" & cursorbegin & "order by id desc) order by ID"
Case "Next"
Sqlstr = "select top" & defrecordnum & "ID, title, filename, K, imgsize, nameson from ABC where ID>" & cursorend &_
"Order by ID"
End select
Set rs = conn. Execute (sqlstr, 0, 1)
%>
<HTML>
<Head>
<Title> "infinite stream" Paging program Author: arbiter </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Style type = "text/CSS"> TD, BR, Div, P, body {font-size: 12px} </style>
</Head>
<Body bgcolor = "# ffffff" leftmargin = "0" topmargin = "0">
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "3" bgcolor = "# e2f5fe">
<Tr align = "center">
<TD colspan = "2"> <% response. Write curpagenum & "/" & totalpages & "Total number of page records:" & totalrecords %> </TD>
<TD> <a href = "mllist. asp"> homepage </a> <a href = javascript: turnpage ('back');> previous page </a>
<A href = javascript: turnpage ('Next');> next page </a> </TD>
</Tr>
</Table>
<Table width = "100%" border = "1" cellspacing = "0" cellpadding = "3" bgcolor = "# cccccc">
<Tr>
<TD> id </TD>
<TD> title </TD>
<TD> filename </TD>
<TD> size </TD>
<TD> size </TD>
<TD> Category </TD>
</Tr>
<%
Turnpagefs (defrecordnum)
Rs. Close
Set rs = nothing
Conn. Close
Set conn = nothing
%>
</Table>
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "3" bgcolor = "# e2f5fe">
<Tr align = "center">
<TD colspan = "2"> <% response. Write curpagenum & "/" & totalpages & "Total number of page records:" & totalrecords %> </TD>
<TD> <a href = "mllist. asp"> homepage </a> <a href = javascript: turnpage ('back');> previous page </a>
<A href = javascript: turnpage ('Next');> next page </a> </TD>
</Tr>
</Table>
<%
Endtime = Timer
Response. Write "<br> program execution time:" & (endtime-begintime) * 1000 & "millisecond"
Response. write "the id value (cursorbegin) of the first record =" & cursorbegin &""
Response. write "the id value (cursorend) of the last record =" & cursorend & "<br>"
%>
<Script language = "JavaScript">
Function turnpage (func ){
VaR curpagenum = <% = curpagenum %>; // obtain the current page number
VaR cursorbegin = <% = cursorbegin %>; // obtain the id value of the first displayed record
VaR cursorend = <% = cursorend %>; // obtain the ID of the last displayed record
VaR totalpages = <% = totalpages %>; // retrieves the total number of pages

var backurl = 'mllist. asp? Curpagenum = '+ (CurPageNum-1) +' & cursorbegin = '+ cursorbegin +' & cursorend = '+ cursorend +' & hav = back';
var nexturl = 'mllist. asp? Curpagenum = '+ (curpagenum + 1) +' & cursorbegin = '+ cursorbegin +' & cursorend = '+ cursorend +' & hav = next ';
If (curpagenum <= 1 & func = 'back') {
location. href = '#';
}else if (curpagenum >=totalpages & func = 'Next') {
location. href = '#';
}else if (func = 'back') {
location. href = backurl;
}else if (func = 'Next') {
location. href = nexturl;
}< BR >}< br>


references: http://hi.baidu.com/happyredtea/blog/item/82dc965868d2c680800a18a9.html

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.