我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > ASP专区 > Asp组件/脚本 > 面向对象的asp编程之五--adodb的类封装
热门文章排行
热门文章排行 手推车”功能的实现(10-07)
八大法则防范ASP网站漏洞(10-23)
ASP教程十一、调试ASP脚本(10-23)
在JSP中访问数据库大全(10-23)
虚机服务中常见Asp.Net低级错误一览(03-21)
精采文章排行
精采文章排行 ASP.NET实现抓取网页中的链接(11-15)
ASP连接数据库的11种方法(11-10)
如何动态创建网页的RSS内容摘要(11-10)
ASP网站漏洞及入侵防范方法(11-10)
ASP自定义函数:对字符串正则替换(11-10)
技术专题推荐
网管论坛交流
 

面向对象的asp编程之五--adodb的类封装 

作者:佚名   来源:一亩三分地   点击:   日期:2007-03-28

<Script language="vbscript" runat="server">
'****************************************************************
' Script Compont Object Model
' Design for Active Server Pages
' Copyright 2004 Version 2.0
' Made by 尹曙光
' ****************************************************************
'
' ADODB的类封装
'
'*****************************************************************
'#################################################################
Function CreateCAdoConnection()
set CreateCAdoConnection=new CAdoConnection
End Function

Class CAdoConnection

Public objAdoConnection

'===============================================================
Public Property Get ConnectionString
ConnectionString=objAdoConnection.ConnectionString
End Property

Public Property Let ConnectionString(ByVal connString)
objAdoConnection.ConnectionString=connString
End Property

'===============================================================
Private Sub Class_Initialize ' Setup Initialize event.

On Error Resume Next

set objAdoConnection=Server.CreateObject("ADODB.Connection")
objAdoConnection.ConnectionTimeout = 15
objAdoConnection.CommandTimeout = 30
objAdoConnection.CursorLocation = 3

End Sub
Private Sub Class_Terminate ' Setup Terminate event.

CloseDbConn()
Set objAdoConnection=nothing

End Sub

'Open Adodb.Connection
Public Sub OpenDbConn(dbLink)
On Error Resume Next
objAdoConnection.ConnectionString=dbLink
OpenDbConn2()
End Sub

Public Sub OpenDbConn2()
On Error Resume Next
CloseDbConn()
objAdoConnection.Open()
if err.number>0 then
Response.Write "打开娄据库失败!"
Response.End
end if
End Sub

Public Sub CloseDbConn()
if objAdoConnection.State=1 then
objAdoConnection.Close
end if
End Sub

Public Function GetConnection()
set GetConnection=objAdoConnection
End Function

Public Sub AdoError()
Response.Write("错误描述 ( 适用于技术人员 ):<br>")
if (objAdoConnection.errors.count>0) then '有错误产生
for i=1 to objConn.errors.count
Response.Write i&":"&objAdoConnection.errors(i-1).description&"<br>"
next 'end of for
set AdoError=true
end if
set AdoError=false
End Sub

Public Function HaveError()
if (objAdoConnection.errors.count>0) then '有错误产生
HaveError=true
else
HaveError=false
end if
End Function
'--------------------------------------------------------------
Public Function Execute(sql)
on Error resume next
objAdoConnection.Execute(sql)
if err.number>0 then
Execute=false
else
Execute=true
end if
End Function

Public Function ExecuteToRs(sql)
on Error resume next
set ExecuteToRs=objAdoConnection.Execute(sql)
End Function
End Class

'#################################################################
Function CreateCAdoRecordSet()
set CreateCAdoRecordSet=new CAdoRecordSet
End Function
Class CAdoRecordSet

Public objAdoRecordSet
Private objAdoCommand
Private objAdoConnection

'==============================================================
Public Property Get cmdCommandType
cmdCommandType=objAdoCommand.CommandType
End Property

Public Property Let cmdCommandType(ByVal cmdType)
objAdoCommand.CommandType=cmdType
End Property
'----------------------
Public Property Get PageSize
PageSize=objAdoRecordSet.PageSize
End Property

Public Property Let PageSize(ByVal iPageSize)
objAdoRecordSet.PageSize=iPageSize
End Property
'--------------------
Public Property Get AbsolutePage
AbsolutePage=objAdoRecordSet.AbsolutePage
End Property

Public Property Let AbsolutePage(ByVal iAbsolutePage)
objAdoRecordSet.AbsolutePage=iAbsolutePage
End Property
'-------------------
Public Property Get RecordCount
RecordCount=objAdoRecordSet.RecordCount
End Property
'-------------------
Public Property Get pageCount
pageCount=objAdoRecordSet.pageCount
End Property
'--------------------
Public Property Get FieldCount
FieldCount=objAdoRecordSet.Fields.Count
End Property
'===============================================================

Private Sub Class_Initialize ' Setup Initialize event.

set objAdoRecordSet=Server.CreateObject("ADODB.RecordSet")
objAdoRecordSet.CacheSize = 10
objAdoRecordSet.CursorType = 3
objAdoRecordSet.CursorLocation = 3
objAdoRecordSet.LockType = 3

set objAdoCommand=Server.CreateObject("ADODB.Command")
objAdoCommand.CommandType = 1

End Sub
Private Sub Class_Terminate ' Setup Terminate event.

CloseRecordSet()
set objAdoRecordSet=nothing
set objAdoCommand=nothing
if objAdoConnection<>Empty then
set objAdoConnection=nothing
end if

End Sub

'---------------------------------------------------------------
Public Sub CloseRecordSet()
if objAdoRecordSet.State=1 then
objAdoRecordSet.Close
end if
End Sub

Public Sub SetConnection(objConnection)
set objAdoConnection=objConnection
set objAdoCommand.ActiveConnection = objAdoConnection
End Sub

Public Sub OpenRecordSet(byval sql)
CloseRecordSet()
objAdoCommand.CommandText=sql
set objAdoRecordSet=objAdoCommand.Execute()
End Sub

Public Sub OpenRecordSet2(sql,conn,CursorType,LockType)
CloseRecordSet()
objAdoRecordSet.Open sql,conn,CursorType,LockType
End Sub

Public Sub cmdExecute(byval sql)
objAdoCommand.CommandText=sql
objAdoCommand.Execute()
End Sub

'---------------------------------------------------------------
Public Function GetFieldValue(byval fieldName)
GetFieldValue=objAdoRecordSet(fieldName).Value
End Function

Public Function GetFieldName(byval fieldOrder)
GetFieldName=objAdoRecordSet(fieldOrder).name
End Function

Public Function SetFieldValue(fieldName,fieldValue)
objAdoRecordSet(fieldName).Value=fieldValue
End Function

Public Function GetBinaryField(fieldName)

End Function

Public Function SetBinaryField(fieldName,fieldValue)

End Function

Public Function RsUpDate()
objAdoRecordSet.Update
End Function

Public Function GetRecordSet()
set GetRecordSet=objAdoRecordSet


文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·ASP中巧用Response属性 ·第六课:ASP脚本循环语句
·在 Web 页上使用条件数值格式 ·连接数据库查询手册(不仅仅适用于asp)
·警惕"给你的FileSystemObject对象加把锁" ·用ASP做全文检索

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。