ADODB.Connection Public dbConn As ADODB.ConnectionPublic stuRs As ADODB.RecordsetPublic SqlFindStr As StringPublic Function Conn2DB() As Boolean'公共Access数据库连函数Dim connStr As StringDim dbName As StringdbName = App.Path & "\" & "Student

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/06 09:43:42

ADODB.Connection Public dbConn As ADODB.ConnectionPublic stuRs As ADODB.RecordsetPublic SqlFindStr As StringPublic Function Conn2DB() As Boolean'公共Access数据库连函数Dim connStr As StringDim dbName As StringdbName = App.Path & "\" & "Student
ADODB.Connection
Public dbConn As ADODB.Connection
Public stuRs As ADODB.Recordset
Public SqlFindStr As String
Public Function Conn2DB() As Boolean
'公共Access数据库连函数
Dim connStr As String
Dim dbName As String
dbName = App.Path & "\" & "StudentDB.mdb"
' Access连接字符串
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbName
Set dbConn = New ADODB.Connection
If dbConn.State adStateOpen Then
dbConn.Open conStr
End If
Conn2DB = True
End Function
Public Function ExcSQL(ByVal sql As String) As ADODB.Recordset
Dim rst As ADODB.Recordset
'执行一条SQL查询,得到一个记录集
Set rst = New ADODB.Recordset
rst.Open Trim$(sql),dbConn,adOpenKeyset,adLockOptimistic
Set ExcSQL = rst
End Function
中间的几局长的代码最不懂是什么意思,还请大虾们指教!

ADODB.Connection Public dbConn As ADODB.ConnectionPublic stuRs As ADODB.RecordsetPublic SqlFindStr As StringPublic Function Conn2DB() As Boolean'公共Access数据库连函数Dim connStr As StringDim dbName As StringdbName = App.Path & "\" & "Student
Public dbConn As ADODB.Connection '定义一个ADODB连接
Public stuRs As ADODB.Recordset '定义Recordset对象
Public SqlFindStr As String
Public Function Conn2DB() As Boolean
'公共Access数据库连函数
Dim connStr As String
Dim dbName As String
dbName = App.Path & "\" & "StudentDB.mdb" '返回程序所在路径
' Access连接字符串
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbName
Set dbConn = New ADODB.Connection '定义一个ADODB连接对象
If dbConn.State adStateOpen Then '判断ADODB连接是否打开
dbConn.Open conStr '如果不是打开状态 就打开连接
End If
Conn2DB = True
End Function
Public Function ExcSQL(ByVal sql As String) As ADODB.Recordset
Dim rst As ADODB.Recordset
'执行一条SQL查询,得到一个记录集
Set rst = New ADODB.Recordset
rst.Open Trim$(sql),dbConn,adOpenKeyset,adLockOptimistic '得到记录
Set ExcSQL = rst
End Function