当前位置: 首页 > 图文教程 > 网络编程 > ASP > 读取数据库中数据到数组的类

ASP
WEB打印设置解决方案四
截取固定长度字符串显示在页面
如何得到上一次插入记录后自动产生的ID
组件:Adodb.Stream 浅释
一个统计当前在线用户的解决方案
实例演练ASP+XML编程
IP地址分段计算
身份证验证代码函数
简单购物车教程
ASP分页函数
asp中对ip进行过滤限制函数
不用Golobal和session实现在线人数统计
ASP实现结构化列举并查看某路径下所有文件
常用Response对象的使用祥解
在ASP网站设计中表单验证
动网论坛代码分析
轻松实现将上传图片到数据库
读取数据库中数据到数组的类
网址和邮件地址的转换函数
ASP编码优化

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 20 ::
收藏到网摘: n/a

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