我的人生路  
日历
<2005年7月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456
统计
  • 随笔 - 74
  • 文章 - 57
  • 评论 - 7
  • 引用 - 0

导航

常用链接

留言簿(5)

随笔分类

随笔档案

文章分类

文章档案

相册

颜色

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 
' ===================================================================
' 读取数据库中数据到数组的类
' 作者:心飞翔
' QQ:85166 E-MAIL:Apwmj@hotmail.com
' 声明:
' 如采用本类模块,请不要去掉这个说明,这段注释不会影响执行的速度.
' 各种用途均可免费使用,但是修改后必须把修改后的文件发送一份给作者.
' 2004年5月18日
' ===================================================================


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



欢迎大家访问我的个人网站 萌萌的IT人
posted on 2005-07-07 14:36 一天一点爱恋 阅读(194) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © 一天一点爱恋 Powered by: 博客园 模板提供:沪江博客