⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module1.bas

📁 英语字典
💻 BAS
字号:
Attribute VB_Name = "Module1"


Public Sub connection()
Dim ConnStr As String   '连接字符串
Dim Cmd As New ADODB.Command   'Cmd是新的ADODB命令
Set cn = New ADODB.connection  'Cn为新的ADODB连接
ConnStr = "DSN = 学习系统.dsn;UID=sa;PWD="
cn.ConnectionString = ConnStr   '建立ODBC连接
cn.Open   '打开数据库
Dim Rs As New ADODB.Recordset
Rs.ActiveConnection = cn '设置连接属性
Rs.CursorType = adOpenStatic
Rs.LockType = adLockPessimistic
End Sub

'======================================================
' 本函数的功能是执行SQL语句,并返回结果集
'======================================================



Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
   Dim Rs As ADODB.Recordset
   Dim ConnStr As String
   Set cn = New ADODB.connection
   Dim sTokens() As String
   On Error GoTo ExecuteSQL_Error
   sTokens = Split(SQL)
   ConnStr = "DSN = 学习系统.dsn;UID=sa;PWD="
   cn.ConnectionString = ConnStr
   cn.Open                                                     '打开连接
   If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then
      cn.Execute SQL
      MsgString = sTokens(0) & " 查询成功"
   Else
      Set Rs = New ADODB.Recordset
      Rs.Open Trim$(SQL), cn, adOpenKeyset, adLockOptimistic
      Set ExecuteSQL = Rs
      MsgString = "查询到" & Rs.RecordCount & " 条记录 "
   End If
ExecuteSQL_Exit:
   Set Rs = Nothing
   Set cn = Nothing
   Exit Function
   
ExecuteSQL_Error:
   MsgString = "查询错误: " & Err.Description
   Resume ExecuteSQL_Exit
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 + -