|
3#
楼主 |
发表于 2010-9-1 07:25:22
|
只看该作者
是用VB编程调用操作Access
在整个程序运行期间,Access一直打开
现在问题是不知如何在运行中关闭。
函数代码如下
Public Function ExecuteSQL(ByVal strSQL As String, strLockType As String) As ADODB.Recordset
Dim rs As New ADODB.Recordset
Dim DBcnn As New ADODB.Connection
On Error GoTo ExecuteSQL_Error
Set DBcnn = New ADODB.Connection
DBcnn.ConnectionString = "uid=admin;pwd=123;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\HR_data_Phone.mdb "
DBcnn.Open
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
If UCase(strLockType) = "W" Then '写数据"w"或"W"
rs.Open Trim$(strSQL), DBcnn, adOpenStatic, adLockPessimistic
Else '只读数据"r"或"R"
rs.Open Trim$(strSQL), DBcnn, adOpenStatic, adLockReadOnly
End If
Set ExecuteSQL = rs
ExecuteSQL_Exit:
Set rs = Nothing
Set DBcnn = Nothing
Exit Function
ExecuteSQL_Error:
If Err.Number <> 0 Then
MsgBox "错误信息:" & Err.Description , vbCritical, "错误"
End If
Resume ExecuteSQL_Exit
End Function
|
|