module1.bas
来自「VB 编写的"华成POS管理系统",代码全,没有进行测试,数据库全,有兴趣的朋友」· BAS 代码 · 共 144 行
BAS
144 行
Attribute VB_Name = "Module1"
Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public addFlag As Boolean
Public Function OpenCn(ByVal Cip As String) As Boolean
Dim mag As String
On Error GoTo strerrmag
readServer
Set conn = New ADODB.Connection
With conn
.ConnectionTimeout = 25
.CursorLocation = adUseClient
.Provider = "SQLOLEDB.1"
.Properties("data source").Value = strSQLServer '服务器的名字"
.Properties("initial catalog").Value = "supermarketdb" '库名
.Properties("integrated security").Value = "SSPI" '登陆类型
.Properties("user id").Value = "sa"
.Properties("password").Value = ""
End With
conn.Open
OpenCn = True
addFlag = True
Exit Function
strerrmag:
mag = "Data can't connect"
Call MsgBox(mag, vbOKOnly, "Error:Data connect")
addFlag = False
Exit Function
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
End
'Exit Function
strerrmag:
mag = "data not connect"
Call MsgBox(mag, vbOKOnly, "error:connect")
openRs = False
End
'Exit Function
End Function
Public Sub cloRs()
On Error Resume Next
If rs.State <> adStateClosed Then rs.Clone
Set rs = Nothing
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?