Access 2000 數(shù)據(jù)庫 80 萬記錄通用快速分頁類
2024-05-04 10:58:18
供稿:網(wǎng)友
 
代碼本人優(yōu)化過,測試通過
主要思路: 用一條語句統(tǒng)計(jì)(Count)出記錄數(shù)(而不在查詢時(shí)獲得 RecordCount 屬性), 緩存在 Cookies 中, 跳轉(zhuǎn)時(shí)就不用再次統(tǒng)計(jì). 使用 ADO 的 AbsolutePage 屬性進(jìn)行頁面跳轉(zhuǎn)即可. 為方便調(diào)用而寫成類, 代碼主要地方已有說明
硬件環(huán)境: AMD Athlon XP 2600+, 256 DDR 
軟件環(huán)境: MS Windows 2000 Advanced Server + IIS 5.0 + Access 2000 + IE 6.0 
測試結(jié)果: 初次運(yùn)行在 250(首頁) - 400(末頁)毫秒, (記錄數(shù)緩存后)在頁面間跳轉(zhuǎn)穩(wěn)定在 47 毫秒以下.第1頁跳到最后一頁不多于 350 毫秒 
適用范圍: 用于普通分頁. 不適用于有較復(fù)雜的查詢時(shí): 如條件為"[Title] Like %最愛%", 查詢的時(shí)間大大增加, 就算 Title 字段作了索引也沒用. :( 
<%
Dim intDateStart
intDateStart = Timer()
Rem ## 打開數(shù)據(jù)庫連接
Rem #################################################################
function f__OpenConn()
Dim strDbPath
Dim connstr
strDbPath = "fenye/db.mdb"
connstr  = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
connstr  = connstr & Server.MapPath(strDbPath)
Set conn  = Server.CreateObject("Adodb.Connection")
conn.open connstr
End function
Rem #################################################################
Rem ## 關(guān)閉數(shù)據(jù)庫連接
Rem #################################################################
function f__CloseConn()
If IsObject(conn) Then
conn.close
End If
Set conn = nothing
End function
Rem #################################################################
Rem 獲得執(zhí)行時(shí)間
Rem #################################################################
function getTimeOver(iflag)
Dim tTimeOver
If iflag = 1 Then
tTimeOver = FormatNumber(Timer() - intDateStart, 6, true)
getTimeOver = " 執(zhí)行時(shí)間: " & tTimeOver & " 秒"
Else
tTimeOver = FormatNumber((Timer() - intDateStart) * 1000, 3, true)
getTimeOver = " 執(zhí)行時(shí)間: " & tTimeOver & " 毫秒"
End If
End function
Rem #################################################################
Class Cls_PageView
Private sbooInitState
Private sstrCookiesName