📄 openrs_cls.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 1 'vbDataSource
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "OpenRs"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private cnSIMS As ADODB.Connection '声明一个连接
Private rsSims As ADODB.Recordset '声明一个连接记录集
Public rs1 As ADODB.Recordset '声明一个连接到所需表的记录集
Public rs2 As ADODB.Recordset
Public rst As ADODB.Recordset
Private Data As Object
'---------------------------------------------------------
' 在类初始化时建立连接
'---------------------------------------------------------
Private Sub Class_Initialize()
On Error GoTo DbnotOpen
Set cnSIMS = New ADODB.Connection
With cnSIMS
.Provider = conProvide
.ConnectionString = conString
.ConnectionTimeout = 10
.Open
Set rst = New ADODB.Recordset
End With
Exit Sub
DbnotOpen:
If Err = -2147467259 Then
Set cnSIMS = Nothing
MsgBox "连接后台数据库失败!" & vbCrLf & vbCrLf & "请检查配置是否完好,数据库Sims_four是否存在?", vbOKOnly + vbInformation, "学生信息管理系统"
End
End If
End Sub
'---------------------------------------------------------
'data是一个指向ADO记录集的对象的引用
'用于设置class的数据源内容
'---------------------------------------------------------
Private Sub Class_GetDataMember(DataMember As String, Data As Object)
Set Data = rsSims
End Sub
'-------------------------------------------------------
'建立一个可以打开记录集的函数,需要是必须把表名传给函数
'-------------------------------------------------------
Public Function rsDK(Table As String)
Set rsSims = New ADODB.Recordset
With rsSims
.Source = Table
.ActiveConnection = cnSIMS
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdTable
End With
End Function
'-------------------------------------------------------
'建立一个可以打开记录集(动态游标)的函数
'需要把SQL语句传递给函数
'-------------------------------------------------------
Public Function rsDK1(sql As String)
Set rs1 = New ADODB.Recordset
With rs1
.Source = sql
.ActiveConnection = cnSIMS
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdText
End With
End Function
'-------------------------------------------------------
'建立一个可以打开记录集(静态游标)的函数
'需要把SQL语句传递给函数
'-------------------------------------------------------
Public Function rsDK2(sql As String)
Set rs2 = New ADODB.Recordset
With rs2
.Source = sql
.ActiveConnection = cnSIMS
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open , , , , adCmdText
End With
End Function
'-------------------------------------------------------
'类终止时,释放一切可能占据的资源
'-------------------------------------------------------
Private Sub Class_Terminate()
Set cnSIMS = Nothing
Set rs1 = Nothing
Set rs2 = Nothing
Set rsSims = Nothing
Set rst = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -