'----******************** TConnString *****************************----
'数据库连接字符串结构体
Class TConnString
Public DBName,DBPath,DBServer,DBUser,DBPass,DBType
End Class
'----******************** TConnString *****************************----
'----********************* TDBOperate *****************************----
'通用数据库操作类
Class TDBOperate
Private cls_oConn,cls_oRS '类私有Connection对象、RecordSet对象
Private cls_sErrInfo,cls_sConn,cls_sSQL,cls_sURL,cls_sFormAction
Private cls_iPageSize '分页数
Private cls_lTotalPage,cls_lTotalRecord,cls_lPageNo
'类初始化
Private Sub Class_Initialize()
End Sub
'*****************************************
' 类型: 属性
' 目的: 根据获取的Connection String,创建数据库连接
' 输入: a_sConn:数据类型字符串
' 返回: 无
'*****************************************
Public Property Let SetConn(a_sConn)
Dim sObjType
sObjType = LCase(TypeName(a_sConn))
If sObjType <> "string" Then
cls_sErrInfo = cls_sErrInfo & "<li>SetConn:非法的字符串参数</li>" & Chr(10)
Exit Property
End If
Set cls_oConn = CreateObject("Adodb.Connection")
On Error Resume Next
cls_oConn.Open a_sConn
If Err Then
Err.Clear
Set cls_oConn = Nothing
On error goto 0
cls_sErrInfo = cls_sErrInfo & "<li>数据库连接出错</li>" & Chr(10)
End If
On Error Goto 0
End Property
'*****************************************
' 类型: 属性
' 目的: 根据获取的Connection对象,创建数据库连接
' 输入: a_oConn:数据类型字符串
' 返回: 无
'*****************************************
Public Property Set SetConn(a_oConn)
Dim sObjType,sConn
Dim oConnStr
sObjType = LCase(TypeName(a_oConn))
Select Case sObjType
Case "connection"
'设置Connection对象
Set cls_oConn = a_oConn
Case "tconnstring"
sConn = ""
Set oConnStr = a_oConn
Select Case (oConnStr.DBType)
Case gbl_iDB_
Access sConn = "Provider = micorsoft.jet.oledb.4.0; User ID = " & oConnStr.DBUser & "; Password = " & Replace(oConnStr.DBPass, Chr(0), "") & ";Initial Catalog = " & oConnStr.DBName & "; Data Source = " & SqlLocalName & ";"
Case gbl_iDB_
MsSQL sConn = "Provider = Sqloledb; User ID = " & oConnStr.DBUser & "; Password = " & Replace(oConnStr.DBPass, Chr(0), "") & ";Initial Catalog = " & oConnStr.DBName & "; Data Source = " & oConnStr.DBServer & ";"
End Select
If sConn = "" Then
cls_sErrInfo = cls_sErrInfo & "<li>数据库连接对象出错,无法创建Connection对象</li>" & Chr(10)
Exit Property
End If
'设置Connection连接串值,供ConnStr属性返回
cls_sConn = sConn
Set cls_oConn = CreateObject("Adodb.Connection")
On Error Resume Next
cls_oConn.Open sConn
If Err Then
Err.Clear
Set cls_oConn = Nothing
cls_sErrInfo = cls_sErrInfo & "<li>数据库连接出错</li>" & Chr(10)
End If
On Error Goto 0
Case Else
cls_sErrInfo = cls_sErrInfo & "<li>SetConn:非法的对象参数</li>" & Chr(10)
Exit Property
End Select
End Property
'*****************************************
' 类型: 属性
' 目的: 设置RecordSet对象
' 输入: a_sSQL: SQL语句。
' 返回: 无。
'*****************************************
Public Property Let SetRS(a_sSQL)
If LCase(TypeName(cls_oConn)) <> "connection" Then
cls_sErrInfo = cls_sErrInfo & "<li>非法的Connection对象,无法创建RecordSet对象</li>" & Chr(10)
Exit Property
End If
cls_sSQL = a_sSQL
'创建RecordSet对象
Set cls_oRS = CreateObject("Adodb.RecordSet")
' On Error Resume Next
cls_oRS.Open cls_sSQL,cls_oConn,1,1
' On Error Goto 0
End Property
'*****************************************
' 类型: 属性
' 目的: 设置RecordSet对象
' 输入: a_oRS: RecordSet对象
' 返回: 无。
'*****************************************
Public Property Set SetRS(a_oRS)
If LCase(TypeName(a_oRS))<>"recordset" Then
cls_sErrInfo = cls_sErrInfo & "<li>非法的RecordSet对象</li>" & Chr(10)
Exit Property
End If
'设置RecordSet对象
Set cls_oRS = a_oRS
End Property
'*****************************************
' 类型: 属性
' 目的: 设置RecordSet对象
' 输入: a_oRS: RecordSet对象
' 返回: 返回一RecordSet对象
'*****************************************
Public Property Get GetRS()
Set GetRS = cls_oRS
End Property
'获取Connection对象
Public Property Get GetConn()
If cls_sErrInfo <> "" Then
Call ShowError()
End If
If LCase(TypeName(cls_oConn))<>"connection" Then
cls_sErrInfo = cls_sErrInfo & "<li>Connection对象获取失败</li>"
' Exit Property
End If
Set GetConn = cls_oConn
End Property
'返回数据库连接字符串
Public Property Get ConnStr
ConnStr = cls_sConn
End Property
'设置第个页面显示的数据数
Public Property Let PageSize(a_iPageSize)
If Not IsNumeric(a_iPageSize) Then
cls_sErrInfo = cls_sErrInfo & "<li>无效的分页记录数参数</li>" & Chr(10)
Exit Property
End If
cls_iPageSize = a_iPageSize
End Property
'设置SQL语句,用于建立RecordSet对象
Public Property Let SQL(a_sSQL)
If IsNone(a_sSQL) Then
cls_sErrInfo = cls_sErrInfo & "<li>没有设置SQL,无法创建RecordSet对象</li>" & Chr(10)
Exit Property
End If
cls_sSQL = Trim(a_sSQL)
End Property
'执行数据操作
Public Sub Execute()
If cls_sErrInfo <> "" Then
ShowError("<ul>" & Chr(10) & cls_sErrInfo & "</ul>" & Chr(10))
Exit Sub
End If
If LCase(TypeName(cls_oConn))="connection" Then
If IsNumeric(cls_iPageSize) Then
Set cls
上一个:能不能在flas易做图中给asp传递变量?
下一个:XML+XSL+CSS+ASP打造留言簿