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

DbPath = "test.mdb"’数据库位置 ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(DbPath) Set Conn = Server.CreateObject("ADODB.Connection") Conn.open ConnStr Class Class_Read Public Arr,Rs,SQL,ArrTR,ArrTD,Page,TotalRead,TotalPage Public Function Read(SQL,TD,TR,PG) SQL = Replace(SQL,"’","") Page= Int(PG) Set Rs = Server.CreateObject("ADODB.Recordset") : Rs.open SQL,conn,1,1 TotalRead= Rs.RecordCount If TotalRead>0 Then If TR>0 Then : Rs.PageSize = TR : Else : TR=TotalRead If TD>Rs.Fields.Count or TD<1 Then TD = Rs.Fields.Count If TotalRead Mod TR <>0 Then TotalPage = 1 : End If : TotalPage = TotalPage + Int(TotalRead/TR) If Page>=TotalPage Then Page=TotalPage : TR = TotalRead-TR*(TotalPage-1) If Page>1 Then Rs.absolutePage=Page Else Page=1 End If reDim Arr(TD-1,TR) For ArrTR = 0 to TR-1 : If Rs.Eof Then Exit For For ArrTD = 0 to TD-1 : Arr(ArrTD,ArrTR) = Rs(ArrTD) : Next : Rs.MoveNext Next ArrTR = ArrTR-1 Rs.Close Set Rs=Nothing End Function End Class ’使用方法 Dim C:Set C = New Class_Read C.Read ("SQL语句","读取列数","读取行数[既每页显示条数]","当前页数") Dim i For i=0 To C.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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值