分享
 
 
 

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

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

<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

End Function

'---------------------------------------------------------------

Function IsEmpty()

IsEmpty=(objAdoRecordSet.BOF and objAdoRecordSet.EOF)

End Function

Function IsEof()

IsEof=objAdoRecordSet.EOF

End Function

Function IsBof()

IsBof=objAdoRecordSet.BOF

End Function

'---------------------------------------------------------------

Function MoveFirst()

objAdoRecordSet.MoveFirst

End Function

Function MovePrevious()

if (not objAdoRecordSet.BOF) then

objAdoRecordSet.MovePrevious

end if

End Function

Function MoveNext()

if (not objAdoRecordSet.BOF) then

objAdoRecordSet.MoveNext

end if

End Function

Function MoveLast()

objAdoRecordSet.MoveLast

End Function

End Class

'#################################################################

Function CreateCAdoCommand()

set CreateCAdoCommand=new CAdoCommand

End Function

Class CAdoCommand

Public objAdoCommand

'==============================================================

Public Property Get cmdCommandType

cmdCommandType=objAdoCommand.CommandType

End Property

Public Property Let cmdCommandType(ByVal cmdType)

objAdoCommand.CommandType=cmdType

End Property

'===============================================================

Private Sub Class_Initialize ' Setup Initialize event.

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

objAdoCommand.CommandType = 1

End Sub

Private Sub Class_Terminate ' Setup Terminate event.

set objAdoCommand=nothing

End Sub

Public Sub cmdExecute()

End Sub

End Class

</Script>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有