?? modsql.bas
字號:
Attribute VB_Name = "modSQL"
'超市銷售系統
'程序開發:lc_mtt
'CSDN博客:http://blog.csdn.net/lc_mtt/
'個人主頁:http://www.3lsoft.com
'郵箱:3lsoft@163.com
'注:此代碼禁止用于商業用途。有修改者發我一份,謝謝!
'---------------- 開源世界,你我更進步 ----------------
Public strSQLServer As String 'SQL服務器地址
Public strSQLUser As String 'SQL用戶名
Public strSQLPW As String 'SQL密碼
Public strSQLDB As String 'SQL數據庫
Public cnMain As New ADODB.Connection '主連接
'連接SQL服務器
Public Function sqlConnect(ByVal cnThis As ADODB.Connection, ByVal strServer As String, ByVal strUser As String, ByVal strPass As String, Optional ByVal strDataBase As String = "")
Dim strSQL As String
'生成連接字符串
strSQL = "provider=sqloledb;server=" & strServer & ";user id=" & strUser & ";password=" & strPass
If strDataBase <> "" Then strSQL = strSQL & ";database=" & strDataBase '如果需要連接到數據庫
cnThis.Open strSQL
End Function
'讀取SQL服務器配置信息
Public Sub readServer()
On Error GoTo aaaa
Dim strTmp As String, strT() As String
Open GetApp & "Files\sql.inf" For Input As #1
If EOF(1) = False Then Line Input #1, strTmp
Close #1
strTmp = Trim(strTmp)
If strTmp <> "" Then
strT = Split(strTmp, "||")
For i = 0 To 3
strT(i) = strT(i)
Next
strSQLServer = strT(0)
strSQLUser = strT(1)
strSQLPW = strT(2)
strSQLDB = strT(3)
End If
Exit Sub
aaaa:
strSQLServer = ""
strSQLUser = ""
strSQLPW = ""
strSQLDB = ""
End Sub
'保存SQL服務器配置信息
Public Sub SaveServer(ByVal strServer As String, ByVal strUser As String, ByVal strPass As String, ByVal strDataBase)
On Error GoTo aaaa
Open GetApp & "Files\sql.inf" For Output As #1
Print #1, strServer & "||" & strUser & "||" & strPass & "||" & strDataBase
Close #1
Exit Sub
aaaa:
MsgBox "保存 SQL 服務器信息失敗!", vbCritical
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -