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

📄 module1.bas

📁 一个图书管管理软件
💻 BAS
字号:
Attribute VB_Name = "Module1"
Public cn As ADODB.Connection
Public rst As ADODB.Recordset

Public Function CnToDB() As Boolean
    On Error GoTo My_Debug
'    If con.State = adStateOpen Then
'        con.Close
'    End If
     Set cn = New ADODB.Connection
    With cn
            .ConnectionString = "provider=sqloledb;uid=sa;pwd=;server=."
            .ConnectionTimeout = 5
            .CursorLocation = adUseClient
            .Open
            .DefaultDatabase = "booksys"
    End With
    CnToDB = True
    Exit Function
My_Debug:
    Set con = Nothing
    CnToDB = False
End Function

Public Function QueryData(ByVal strSql As String) As Boolean
    On Error GoTo My_Debug
    If CnToDB = True Then
        Set rst = New ADODB.Recordset
       With rst
            .Source = strSql
            .ActiveConnection = cn
            .CursorLocation = adUseClient
            .CursorType = adOpenDynamic
            .LockType = adLockOptimistic
            .Open
    End With
        QueryData = True
    End If
    Exit Function
My_Debug:
    Set rst = Nothing
    QueryData = False
End Function

Public Function getRS(ByRef rst As ADODB.Recordset, ByVal strSql As String) As Boolean
On Error GoTo rsErr
    Set rst = New ADODB.Recordset
    With rst
            .Source = strSql
            .ActiveConnection = cn
            .CursorLocation = adUseClient
            .CursorType = adOpenDynamic
            .LockType = adLockOptimistic
            .Open
    End With
    If rst.State Then
        getRS = True
        Exit Function
    End If
rsErr:
    getRS = False
    MsgBox Err.Number & Err.Description, vbCritical + vbOKOnly, "错误信息"
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -