?? module1.bas
字號:
Attribute VB_Name = "Module1"
Option Explicit
'判斷登陸是否成功
Public OK As Boolean
Public UserName As String
Public fMainForm As New frmMain
'傳遞參數SQL傳遞查詢語句,MsgString傳遞查詢信息
'自身以一個數據集對象的形式返回
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) _
As ADODB.Recordset
'定義連接
Dim cnn As ADODB.Connection
'定義結果集
Dim rst As ADODB.Recordset
'定義字符串
Dim sTokens() As String
'異常處理
On Err GoTo ExecuteSQL_Error
'用函數split產生一個包含各個子串的數組
sTokens = Split(SQL)
'創立連接
Set cnn = New ADODB.Connection
'打開連接
cnn.Open ConnectString
'判斷字符串是否含有指定內容
If InStr("INSERT,UPDATE,DELET", UCase$(sTokens(0))) Then
'執行查詢語句
cnn.Execute SQL
'返回查詢信息
MsgString = sTokens(0) & "query successful"
Else
'創建數據集對象
Set rst = New ADODB.Recordset
'返回查詢結果
'
rst.Open Trim(SQL), cnn, adOpenKeyset, adLockOptimistic
' rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
' rst.MoveLast get recordcount
'返回結果集對象
Set ExecuteSQL = rst
MsgString = "查詢到" & rst.RecordCount & "條記錄"
End If
ExecuteSQL_Exit:
'清空數據集對象
Set rst = Nothing
'中斷連接
Set cnn = Nothing
Exit Function
'錯誤類型判斷
ExecuteSQL_Error:
MsgString = "查詢錯誤" & Err.Description
Resume ExecuteSQL_Exit
End Function
Public Function ConnectString() As String
'返回一個數據庫連接
ConnectString = "FileDSN=mycon.dsn;UID=sa;PWD=;initial catalog=stumag"
' ConnectString = "provider=sqloledb;data source=.;user id=sa;initial catalog=stumag"
End Function
Public Function Testtxt(txt As String) As Boolean
'判斷輸入是否為空
If Trim(txt) = "" Then
Testtxt = False
Else
Testtxt = True
End If
End Function
Sub Main()
Dim fLogin As New frmLogin
'顯示登陸窗體
fLogin.Show vbModal
fLogin.Show vbModal
'判斷是否是授權用戶
If Not fLogin.OK Then
End
End If
Unload fLogin
'判斷是將進入系統
Set fMainForm = New frmMain
fMainForm.Show
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -