处理分页的数据函数GetlistByPage(strSQL, PageSize, PageNo, PageCount, arrList)

'-------------------------------------------
'strSQL:标准的SQL语句
'PageSize:每页的纪录数
'PageNo:第几页
'PageCount:总页数
'arrList:存放数据的二维数组
'------------------------------------------
Function GetListByPage(strSQL, PageSize, PageNo, PageCount, arrList)
    On Error Resume Next
    Dim objConn, objRS
        
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.Open Application("connstr")  'Application("connstr") 为数据库连接字符串
    Set objRS = Server.CreateObject("ADODB.RecordSet")
    GetListByPage= False
      
    objRS.Open strSQL, objConn, 1, 1
    If Not objRS.eof And Not objRS.bof Then
       objRS.PageSize = Int(PageSize)
       PageCount = objRS.PageCount
       if PageNo < 0 then PageNo = 1
       if int(PageNo) > int(PageCount) then PageNo = PageCount
          objRS.AbsolutePage = PageNo
          arrList=objRS.GetRows(PageSize)
          GetListByPage= True
       else
          PageCount = 0
    end if
    objRS.Close
    Set objRS = nothing
    objConn.close
    Set objConn = Nothing
   
    if err.Number > 0 then GetListByPage= False
End Function

下一篇介绍与该函数紧密配合的分页函数

posted on 2005-08-08 17:32  有容乃大 无欲则刚  阅读(2213)  评论(0编辑  收藏  举报

导航