Access 2000 數據庫 80 萬記錄通用快速分頁類
2024-05-04 11:01:53
供稿:網友
代碼本人優化過,測試通過
主要思路: 用一條語句統計(Count)出記錄數(而不在查詢時獲得 RecordCount 屬性), 緩存在 Cookies 中, 跳轉時就不用再次統計. 使用 ADO 的 AbsolutePage 屬性進行頁面跳轉即可. 為方便調用而寫成類, 代碼主要地方已有說明
硬件環境: AMD Athlon XP 2600+, 256 DDR
軟件環境: MS Windows 2000 Advanced Server + IIS 5.0 + Access 2000 + IE 6.0
測試結果: 初次運行在 250(首頁) - 400(末頁)毫秒, (記錄數緩存后)在頁面間跳轉穩定在 47 毫秒以下.第1頁跳到最后一頁不多于 350 毫秒
適用范圍: 用于普通分頁. 不適用于有較復雜的查詢時: 如條件為"[Title] Like %最愛%", 查詢的時間大大增加, 就算 Title 字段作了索引也沒用. :(
<%
Dim intDateStart
intDateStart = Timer()
Rem ## 打開數據庫連接
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 ## 關閉數據庫連接
Rem #################################################################
function f__CloseConn()
If IsObject(conn) Then
conn.close
End If
Set conn = nothing
End function
Rem #################################################################
Rem 獲得執行時間
Rem #################################################################
function getTimeOver(iflag)
Dim tTimeOver
If iflag = 1 Then
tTimeOver = FormatNumber(Timer() - intDateStart, 6, true)
getTimeOver = " 執行時間: " & tTimeOver & " 秒"
Else
tTimeOver = FormatNumber((Timer() - intDateStart) * 1000, 3, true)
getTimeOver = " 執行時間: " & tTimeOver & " 毫秒"
End If
End function
Rem #################################################################
Class Cls_PageView
Private sbooInitState
Private sstrCookiesName