Access2000数据库80万记录通用快速分页类
2008-02-23 05:30:33来源:互联网 阅读 ()
主要思路: 用一条语句统计(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)
If Value <> "" Then
sstrOrderList = " ORDER BY " & Value
Else
sstrOrderList = ""
End If
End Property
Rem ## 用于统计记录数的字段
Public Property Let strPrimaryKey(Value)
sstrPrimaryKey = Value
End Property
Rem ## 每页显示的记录条数
Public Property Let intPageSize(Value)
sintPageSize = toNum(Value, 20)
End Property
Rem ## 数据库连接对象
Public Property Let objConn(Value)
Set sobjConn = Value
End Property
Rem ## 当前页
Public Property Let intPageNow(Value)
sintPageNow = toNum(Value, 1)
End Property
Rem ## 页面参数
Public Property Let strPageVar(Value)
sstrPageVar = Value
End Property
Rem ## 是否刷新. 1 为刷新, 其他值则不刷新
Public Property Let intRefresh(Value)
sintRefresh = toNum(Value, 0)
End Property
Rem ## 获得当前页
Public Property Get intPageNow()
intPageNow = singPageNow
End Property
Rem ## 分页信息
Public Property Get strPageInfo()
strPageInfo = sstrPageInfo
End Property
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:模仿PHP写的ASP分页
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash