Access2000資料庫80萬記錄通用快速分頁類

來源:互聯網
上載者:User
access|分頁|資料|資料庫 剛用的,不錯。給大家看看
   主要思路: 用一條語句統計(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 欄位作了索引也沒用. :(
<%@LANGUAGE = "VBScript" CODEPAGE="936"%>
<%Option Explicit%>
<%
Dim intDateStart
intDateStart = Timer()
Rem ## 開啟資料庫連接
Rem #################################################################
  function f__OpenConn()
   Dim strDbPath
   Dim connstr
   strDbPath = "../db/test.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
  Private sstrPageUrl
  Private sstrPageVar
  Private sstrTableName
  Private sstrFieldsList
  Private sstrCondiction
  Private sstrOrderList
  Private sstrPrimaryKey
  Private sintRefresh
  
  Private sintRecordCount
  Private sintPageSize
  Private sintPageNow
  Private sintPageMax
  
  Private sobjConn
  
  Private sstrPageInfo
  
  Private Sub Class_Initialize
   Call ClearVars()
  End Sub
   
  Private Sub class_terminate()
   Set sobjConn = nothing
  End Sub
  
  Public Sub ClearVars()
   sbooInitState = False
   sstrCookiesName = ""
   sstrPageUrl = ""
   sstrPageVar = "page"
   sstrTableName = ""
   sstrFieldsList = ""
   sstrCondiction = ""
   sstrOrderList = ""
   sstrPrimaryKey = ""
   sintRefresh = 0
   
   sintRecordCount = 0
   sintPageSize = 0
   sintPageNow = 0
   sintPageMax = 0
  End Sub
  
  Rem ## 儲存記錄數的 Cookies 變數
  Public Property Let strCookiesName(Value)
   sstrCookiesName = Value
  End Property
  
  Rem ## 轉向地址
  Public Property Let strPageUrl(Value)
   sstrPageUrl = Value
  End Property
  
  Rem ## 表名
  Public Property Let strTableName(Value)
   sstrTableName = Value
  End Property
  
  Rem ## 欄位列表
  Public Property Let strFieldsList(Value)
   sstrFieldsList = Value
  End Property
  
  Rem ## 查詢條件
  Public Property Let strCondiction(Value)
   If Value <> "" Then
    sstrCondiction = " WHERE " & Value
   Else
    sstrCondiction = ""
   End If
  End Property
  
  Rem ## 排序欄位, 如: [ID] ASC, [CreateDateTime] DESC
  Public Property Let strOrderList(Value)



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。