這個分頁使用的是0游標,也就是Rs.Open Sql,Conn,0,1。但是感覺也快不了多少,10萬條數據的分頁時間300多豪秒之間。
複製代碼代碼如下:
<%
'******************************
'名稱:分頁類
'日期:2005/12/3
'作者:西樓冷月
'網址:www.xilou.net | www.chinaCMS.org
'描述:無
'版權:轉載請註名出處,作者
'******************************
Class Page
Private CurrPage
Private PageN
Private UrlStr
Private TempStr
Private ErrInfo
Private IsErr
Private TotalRecord
Private TotalPage
Public PageRs
Private TempA(11)
Private TempB(8)
'------------------------------------------------------------
Private Sub Class_Initialize()
CurrPage=1'//默認顯示當前頁為第一頁
PageN=10'//默認每頁顯示10條數據
UrlStr="#"
TempStr=""
ErrInfo="ErrInfo:"
IsErr=False
End Sub
Private Sub Class_Terminate()
If IsObject(PageRs) Then
PageRs.Close
Set PageRs=Nothing
End If
Erase TempA
Erase TempB
End Sub
'----------------------------------------------------------
'//獲取當前頁碼
Public Property Let CurrentPage(Val)
CurrPage=Val
End Property
Public Property Get CurrentPage()
CurrentPage=CurrPage
End Property
'//獲取每頁顯示條數
Public Property Let PageNum(Val)
PageN=Val
End Property
Public Property Get PageNum()
PageNum=PageN
End Property
'//獲取URL
Public Property Let Url(Val)
UrlStr=Val
End Property
Public Property Get Url()
Url=UrlStr
End Property
'//獲取模板
Public Property Let Temp(Val)
TempStr=Val
End Property
Public Property Get Temp()
Temp=TempStr
End Property
'------------------------------------------------------------
Public Sub Exec(Sql,ConnObj)
On Error Resume Next
Set PageRs=Server.CreateObject("ADODB.RecordSet")
PageRs.CursorLocation = 3 '使用客戶端游標,可以使效率提高
PageRs.PageSize = PageN '定義分頁記錄集每頁顯示記錄數
PageRs.Open Sql,ConnObj,0,1
If Err.Number<>0 Then
Err.Clear
PageRs.Close
Set PageRs=Nothing
ErrInfo=ErrInfo&"建立或打開記錄集錯誤..."
IsErr=True
Response.Write ErrInfo
Response.End
End If
TotalRecord=PageRs.RecordCount'//如果為0呢?
If TotalRecord>=1 Then
'----------------------------------------------------------------------------開始
'//計算總頁數,Ps,為什麼不用PageRs.PageCount呢?
'If TotalRecord Mod PageN=0 Then
'TotalPage=PageRs.RecordCount/PageN
'Else
'TotalPage=PageRs.RecordCount/PageN
'TotalPage=Abs(Int(TotalPage))
'End If
TotalPage=PageRs.PageCount
'//處理當前接收頁碼,默認的為1,所以不是數字類型的都會為1
If IsNumeric(CurrPage) Then