读取数据库中数据到数组的类

2018-09-06 11:22

阅读:492

  DbPath=test.mdb’数据库位置
ConnStr=Provider=Microsoft.Jet.OLEDB.4.0;DataSource=Server.MapPath(DbPath)
Conn.openConnStr

ClassClass_Read
PublicArr,Rs,SQL,ArrTR,ArrTD,Page,TotalRead,TotalPage
PublicFunctionRead(SQL,TD,TR,PG)
SQL=Replace(SQL,’,)
Page=Int(PG)
SetRs=Server.CreateObject(ADODB.Recordset):Rs.openSQL,conn,1,1
TotalRead=Rs.RecordCount
IfTotalRead>0Then
IfTR>0Then:Rs.PageSize=TR:Else:TR=TotalRead
IfTD>Rs.Fields.CountorTD<1ThenTD=Rs.Fields.Count
IfTotalReadModTR<>0ThenTotalPage=1:EndIf:TotalPage=TotalPage+Int(TotalRead/TR)
IfPage>=TotalPageThenPage=TotalPage:TR=TotalRead-TR*(TotalPage-1)
IfPage>1ThenRs.absolutePage=PageElsePage=1
EndIf
reDimArr(TD-1,TR)
ForArrTR=0toTR-1:IfRs.EofThenExitFor
ForArrTD=0toTD-1:Arr(ArrTD,ArrTR)=Rs(ArrTD):Next:Rs.MoveNext
Next
ArrTR=ArrTR-1
Rs.Close
SetRs=Nothing
EndFunction
EndClass
’使用方法
DimC:SetC=NewClass_Read
C.Read(SQL语句,读取列数,读取行数[既每页显示条数],当前页数)
Dimi
Fori=0ToC.ArrTR
Response.Write<br>内容:C.Arr(0,i)
Next
Response.Write<br>总记录条数:C.TotalRead
Response.Write<br>总页数:C.TotalPage
Response.Write<br>当前页:C.Page
Response.Write<br>当前记录数:C.ArrTR+1


评论


亲,登录后才可以留言!