如果你有密码可以采用以下的方法: 以下是一个执行SQL语句的函数Public Function ExecuteSQL(ByVal sql _ As String, MsgString As String) _ As ADODB.Recordset
ConnectString = "DBQ=" & DataBaseName & ";DefaultDir=;Driver={Microsoft Access Driver (*.mdb)};pwd=你的密码" Dim cnn As ADODB.Connection Dim rst As ADODB.Recordset Dim sTokens() As String
On Error GoTo ExecuteSQL_Error
sTokens = Split(sql) Set cnn = New ADODB.Connection cnn.Open ConnectString If InStr("INSERT,DELETE,UPDATE", _ UCase$(sTokens(0))) Then cnn.Execute sql MsgString = sTokens(0) & _ " query successful" Else Set rst = New ADODB.Recordset rst.Open Trim$(sql), cnn, _ adOpenKeyset, _ adLockOptimistic Set ExecuteSQL = rst MsgString = "查询到" & rst.RecordCount & _ " 条记录 " End If Set rst = Nothing Set cnn = Nothing Exit Function ExecuteSQL_Exit: Set rst = Nothing Set cnn = Nothing Exit Function
ExecuteSQL_Error: MsgString = "查询错误: " & _ Err.Description Resume ExecuteSQL_Exit End Function
以下是一个执行SQL语句的函数Public Function ExecuteSQL(ByVal sql _
As String, MsgString As String) _
As ADODB.Recordset
ConnectString = "DBQ=" & DataBaseName & ";DefaultDir=;Driver={Microsoft Access Driver (*.mdb)};pwd=你的密码"
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error
sTokens = Split(sql)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE", _
UCase$(sTokens(0))) Then
cnn.Execute sql
MsgString = sTokens(0) & _
" query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(sql), cnn, _
adOpenKeyset, _
adLockOptimistic
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & _
" 条记录 "
End If
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Error:
MsgString = "查询错误: " & _
Err.Description
Resume ExecuteSQL_Exit
End Function
还有没有其他保护数据的方法?