精彩专题推荐:建站之入门课 建站之必修课 建站之关键课 网站价值所在 流量提高专题 css+div 标准 个人网站打造全过程
返回建站学首页
导航:
建站首页 | 网站设计 | 网站开发 | 网站运营 | 网页软件 | 建站指南 | 搜索优化 | 图像处理 | 视频教程 | 书籍教程 | 建站专题
当前位置:首页>网站开发>ASP教程>正文

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


来源:我要学习网 时间:06-11-12 点击: 点击这里收藏本文
整理:阿炳
网址:http://www.jzxue.com
投稿:(转贴)

 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 
  

  把此文章收藏到:          
广而告之
文章搜索
  • Google JZxue.Com

关于我们 | 联系我们 | 友情链接 | 网站地图
Copyright © 2005 - 2006 建站学 All rights reserved.