Overview
---- Now there are many articles that use ASP to achieve dynamic pagination. The method is similar, that is, each time you use Ado to return the original data to meet the specified page of the conditional concentration. However, in actual engineering applications, the amount of original data is usually very large, and the processing of the original data is relatively slow. If the original data of the page is changed once, it will seriously affect the performance of the application operation.
---- There are two main ways to solve the above problems: one is to relatively fixed the query conditions, use a relatively fixed query condition to process the original data, generate a small data quantity intermediate library. Each query is in the middle to the middle. The library is operated. Although this will improve the performance of the program, it will affect the flexibility of the program, and the server needs to process and maintain the original data regularly. Another way is to save the query on the server side. Although this cannot improve the performance of the query, the Server terminal can respond quickly when the client replacement. The realization of the first way is relatively simple. This article introduces the implementation method of the second way.
Implementation method
---- Save the query results on the server in a dynamic array, that is, declare a two-dimensional dynamic array during the session_onstart process. When the server receives the application submitted by the Client, the first judge whether the application is conditional inquiries or a page change. In this array, the content of the first page is returned to the client, otherwise it will return the corresponding page directly from the array.
Program implementation:
---- 1. Define two -dimensional array and other variables
The following is the code fragment: Sub session_onstart DIM TEMPDB () Redim Preserve Tempdb (1,2) session ("Storedarray") = Tempdb 'Define a session array session ("IpageCount") = 0 session ("ipageno") = 0 ... ... End sub |
---- 2. Call the storage procedure to return the data
The following is the code fragment: Sub GetRCORDSET (Strbbmc, Strkssj, Strzzsj, StrNodeCode, Strfxzl) '' Parameters are report names and various restrictions Select Case Strbbmc Case "Transaction Summary Form" strcnn = "provider = msdasql; dsn = sqldb; uID = SA; pwd = 123456; database = vlog; " Set objcnn = server.createObje ("Adodb.connection") objcnn.commandtimeout = 9999999 objcnn.connectionTimeout = 99999999 objcnn.cursorLocation = AduseClient Objcnn.open Strcnn '' Open the connection Set objrs = server.createObject ("Adodb.recordset") objrs.pageSize = iPageSize objrs.cachesize = iPageSize objrs.open "sszhatmlog '" & strkssj & "' ', '"" "" '"" "" AdlockReadonly, 1 'Perform the storage procedure back to the query results ... ... End sub |
---- 3. Save the query results to the dynamic array
The following is the code fragment: Sub saveRecordSet () if objrs.eof = false then objrs.movelast session ("IROWCount") = Objrs.RcordCount session ("iFieldCount") = objrs.fields.count session ("iPageCount") = Objrs.pageCount Redim Preserve Temparray (Session ("IROWCOUNT"), session ("iFieldCount")) 'Temparray is a two -dimensional dynamic array, Define its size according to the record set size objrs.movefirst icount = 0 do while objrs.eof = false icount = icount + 1 for i = 1 to session ("ifieldcount") Temparray (iCount, I) = Objrs.fields.Item (I -1). Value next objrs.movenext loop session ("Storedarray") = Temparray objrs.close else session ("IpageCount") = 0 end if End sub |
---- 4. Display record content
The following is the code fragment: Sub showRecord () ... ... Localray = session ("Storedarray") iShowtotal = (iPageCurrent -1) * ipAGESIZE + 1 IRowLoop = 1 Do why IRowLoop <= iPageSize and Ishowtotal <= session ("IRowCount") Response.write ("<ter>") for i = 1 to session ("ifieldcount") Response.write ("<TD>" & Localray (ishowtotal, i)) Next Response.write ("< /tr>) iShowtotal = iShowtotal + 1 IRowLoop = IROWLOOP + 1 LOOP Response.write ("< /table>") if iPageCurrent <> 1 and iPageCurrent <session ("IpageCount") then %> <ster> <A href = "db_pag.asp? Page = < % = iPageCurrent -1 %> "> Previous page < /a> <A href = "DB_PAG.ASP? Page = < % = iPageCurrent + 1 %>"> The last page < /a> < /center> < % else if iPageCurrent <> 1 then %> <ster> <A href = "db_pag.asp? Page = < % = iPageCurrent -1 %> "> Previous page < /a> < /center> < % end if if iPageCurrent <session ("iPageCount") %> <center> <a href = "db_pag.asp? Page = < % = IPageCurrent + 1 %> "> Later page < /a> < /center> < % end if end if End sub |