📄 dbconn.bas
字号:
Attribute VB_Name = "DBconn"
Public Function check(str As String) As Boolean 'sql防注入
Dim str1, str2, str3, str4 As String
str1 = "'"
str2 = "="
str3 = "or"
str4 = "!"
If str = "" Then '判断传入的数据是否为空
MsgBox "内容不能为空", , "错误提示"
check = False
Else
If InStr(str, str1) <> 0 Or InStr(str, str2) <> 0 Or InStr(str, str3) <> 0 Or InStr(str, str4) <> 0 Then
MsgBox "你输入的信息当中有非法字符,请重新输入!!", , "错误提示"
check = False
Else
check = True
End If
End If
End Function
Public Function ConnectString(Connstring As String) As String
'returns a DB ConnectString
ConnectString = Connstring
End Function
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
'executes SQL and returns Recordset
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
'__________________________
If conn = True Then
cnn.Open ConnectString(SQLconn)
Else
cnn.Open ConnectString(ACCESSconn)
End If
' cnn.Open ConnectString(Connstring)
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
'rst.MoveLast 'get RecordCount
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & " 条记录 "
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Error:
MsgString = "查询错误: " & Err.Description
Resume ExecuteSQL_Exit
End Function
Public Function TestText(txt As String) As Boolean
If Trim(txt) = "" Then
TestText = False
Else
TestText = True
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -