📄 module1.bas
字号:
Attribute VB_Name = "Module1"
Option Explicit
Public LoginSucceeded As Boolean
Public UserName As String
Public UserType As Integer
' 使用SQL的函数
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
'SQL传递查询语句,MsgString传递查询信息
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
ExecuteSQL_Exit:
Set rst = Nothing '清空数据集对象
Set cnn = Nothing '中断连接
Exit Function
'错误类型判断
ExecuteSQL_Error:
MsgString = "查询错误:" & Err.Description
Resume ExecuteSQL_Exit
End Function
Public Function ConnectString() As String
'ConnectString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=qq;Data Source=NUDT-VTDRY8EAVG" '指明连接数据库
ConnectString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=LLM;Data Source=." '指明连接数据库
End Function
Public Function Testtxt(txt As String) As Boolean
'判断输入内容是否为空
If Trim(txt) = "" Then
Testtxt = False
Else
Testtxt = True
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -