ASP中设计和使用类5

'名称:ado_5do8
'作用:读取数据库的各项操作
'来源-耕耘村http://www.5do8.com http://www.Blueidea.com-5do8
'创作:5do8
'联系:5do8@5do8.com
'更新:2005年11月13日
'授权:蓝色理想网站积分超过3000,耕耘村所有注册用户
'类的接口:ado_5do8.ConnectString=数据库绝对路径
  'ado_5do8.rs_top 调用数目,表的名称
Class ado_5do8
 Private conn,sqlstr,rs,iid,itable,isession
   'sqlstr:数据库地址,为绝对路径,私有
   'conn:打开数据库的连接,私有

'------------------------------------------------------------------
rem 消除一些不想要的数字 
Private Function litter_in(r1,r2)
If IsNumeric(r1) and IsNumeric(r2) Then
 Dim dimrr
 If r1>r2 Then
 dimrr=r2
 Else
 dimrr=r1
 End If
 Else
 dimrr=0
 End if
 litter_in=dimrr
 End Function
'-----------------------------------------------------------------
Private Function killint(i,killstr,killsub)
  If Not IsNumeric(i) Then
  i=killstr
  ElseIf i<=0 Then
  i=killsub
  End if
  killint=Int(Left(i,5))
  End Function
'-----------------------------------------------------------
private Sub startconn()
   On Error Resume Next
    Set conn=server.CreateObject("adodb.connection")
   strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(sqlstr)
   conn.open strconn
   If Err Then
   err.Clear
   Set Conn = Nothing
   mess="发生错误,不能连接数据库"
   response.write(mess)
   response.End
   Else
   mess="连接数据库conn成功...........<br/>"
   response.write(mess)
   End If
   End Sub
'----------------------------------------------------------------
private Sub closeconn()
   conn.close
   Set conn=Nothing
   response.write("<strong style='color:red'>关闭conn连接</strong>...<hr/>")
  End sub
'-----------------------------------------------------------------
Private Sub closers()
  rs.close
  Set rs=Nothing
  response.write("<strong style='color:#085420'>关闭数据库RS</strong>.......<br/>")

  End Sub

'-----------------------------------------------------------------
Property Get havese
  havese=isession
  End Property
 
Property Let havese(yoursession)
  isession=yoursession
  If yoursession="" Then
  isession="nodef"
  End If
  End Property
 
'-----------------------------------------------------------------
Public Function makesession(arraydata)
   If IsArray(arraydata) then
   makear=arraydata
   Else
   makear=Array(0,0,0,0)
   End If
   If isession="" Then
   isession="nodef"
   End if
   session(isession)=makear
   End Function
'-----------------------------------------------------------------

private Function getsession()
  thisget=session(isession)
  If Not IsArray(thisget) Then
  thisget=Array(0,0,0,0)
  End If
  Getsession=thisget
  End function
'-----------------------------------------------------------------
Property Get ConnectString
ConnectString = sqlstr
End Property
Property Let ConnectString(str)
sqlstr = str
End Property
'-----------------------------------------------------------------

Property Get getid
getid = iid
End Property
Property Let getid(id)
iid = id
End Property
'-----------------------------------------------------------------

Property Get gettable
gettable = itable
End Property
Property Let gettable(table)
itable = table
End Property
'-----------------------------------------------------------------
'------------------------------------------------------------------
public Function readarraysession(iStart,ipageno,irowid)
  rowid=killint(irowid,0,0)
  start=killint(istart,0,0)
  pageno=killint(ipageno,5,5)
   data=getsession
  iRows = UBound(data, 2)
  iCols = UBound(data, 1)
  response.write("<h5>总数获得了:")
  response.write("<b> "&iRows+1&"</b>条信息</h5><hr/><ul style='width:100%;'>")
  If rowid = 0 then
  If iRows > (ipageno + iStart) Then
  iStop = ipageno + iStart - 1
  Else
  iStop = iRows
  End If
  For iRowLoop = Start to iStop
  Response.Write ("<li style='padding:4px 0;'><a href=?k=read&rowid="&irowloop+1&">"&data(1, iRowLoop) & " </a><span style='padding:4px 0 4px 10px;background-color:#ccc; '>较慢,不推荐点击--><a href=?k=list&id="&data(0,irowloop)&">更新</a></span></li>")
  Next
  Response.Write "</ul><div style='top:20px;background-color:#ccc;color:#020;font-weight:bold;bordr-top:2px solid #008;padding:10px 0;color:#b00'>列表(<a href=default.asp>回到典型模式</a>):"
  if Start > 0 then
   Response.Write "<A HREF=""?k=read&Start=" & iStart-ipageno &"&pageno=" & ipageno & """>Previous</A>"
  end if
  if iStop < iRows then
  Response.Write " <A HREF=""?k=read&Start=" & iStart+ipageno &"&pageno=" & ipageno & """>Next</A>"
  end If
 
  response.write"</div>"

  Else
  rowid=litter_in(rowid-1,iRows)
  response.write("<div style='width:85%'><h4 style='text-align:center'><a href=?k=read&pageno="&pageno&"&start="&start&">返回列表</a></h4></h2><hr/><h5>"&server.htmlencode(data(1,rowid))&"</h5><p>"&server.htmlencode(data(2,rowid))&"<h5>+-----"&server.htmlencode(data(3,rowid))&"")
  response.write("<div >")
  End if
  End Function
 
'-----------------------------------------------------------------
Public Function list_ids()
  sql3="select * from "&itable&" where id="&iid&" "
  startconn()
  Set rs=conn.execute(sql3)
  If rs.eof And rs.bof Then
  data=Array(0,0,0,0)
  Else
  data=Rs.GetRows()
  End If
  closers
  closeconn
   response.write(UBound(data)&":")
  response.write(server.htmlencode(data(2,0)))
  End function

'-----------------------------------------------------------------
Public Function rs_top(num,table,whe)
  startconn()
  sql="select top "&num&" * from "&table&""
  sql2="select count(*) as szd_count from "&table&" "" "&whe&""
  Set rs=conn.execute(sql2)
  szd_count=rs("szd_count")
  closers
   Set rs = Conn.Execute(sql)
   dim data
  If Rs.Eof Then
  data="no data"
  Else
  data=Rs.GetRows()
  End if
  closers
  closeconn()
  Call makesession (data)
    End Function
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
End Class
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值