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

📄 database.bas

📁 提供给入门级别的GPRS编程人员
💻 BAS
字号:
Attribute VB_Name = "mod_database"
Option Explicit
Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public addFlag As Boolean
Public Function OpenCn() As Boolean
Dim mag As String
On Error GoTo strerrmag
Set conn = New ADODB.Connection
conn.ConnectionTimeout = 25
conn.Provider = "sqloledb"
conn.Properties("data source").Value = "127.0.0.1" '服务器的名字
conn.Properties("initial catalog").Value = "gprspc" '库名
conn.Properties("integrated security").Value = "SSPI" '登陆类型
'conn.Properties("user id").Value = "sa"
'conn.Properties("password").Value = "zyl"
conn.Open
OpenCn = True
addFlag = True
Exit Function
strerrmag:
mag = "无法连接数据库"
Call MsgBox(mag, vbOKCancel, "数据库连接出错")
addFlag = False
End
End Function


Public Sub clocn()
    On Error Resume Next
    If conn.State <> adStateClosed Then conn.Close
    Set conn = Nothing
End Sub

Public Function openrs(ByVal strsql As String) As Boolean '连接数据库记录集
    Dim mag As String
Dim rpy As Boolean
On Error GoTo strerrmag
Set rs = New ADODB.Recordset
If addFlag = False Then rpy = True
With rs
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open strsql
End With
addFlag = True
openrs = True
Exit Function
strerrmag:
mag = "数据连接失败"
Call MsgBox(mag, vbOKCancel, "数据连接出错")
openrs = False
End
End Function
Public Sub clors()
On Error Resume Next
If rs.State <> adStateClosed Then rs.Close
Set rs = Nothing
End Sub

⌨️ 快捷键说明

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