Public fMainForm As frmMain
Public UserName As String
Sub Main()
Dim fLogin As New frmLogin
fLogin.Show vbModal
If Not fLogin.OK Then
'Login Failed so exit app
End
End If
Unload fLogin
Set fMainForm = New frmMain
fMainForm.Show
End Sub
Public Function ConnectString() As String 'returns a DB ConnectString
ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD="
End Function
Public Function ExecuteSQL(ByVal SQL As String,MsgString As String) _
As ADODB.Recordset
'SQL:传递查询语句;MsgString:传递查循信息;自身以一个数据集对象的形式返回
executes SQL and returns Recordset
Dim cnn As ADODB.Connection ‘定义连接
Dim rst As ADODB.Recordset
Dim sTokens() As String ‘定义字符串
On Error GoTo ExecuteSQL_Error ‘异常处理
sTokens = Split(SQL) ‘用Split函数产生一个包涵各个子串的数组
Set cnn = New ADODB.Connection ‘创建连接
cnn.Open ConnectString ‘打开连接
If InStr("INSERT,DELETE,UPDATE",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.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 Testtxt(txt As String) As Boolean ‘判断输入内容是否为空,如果文本框内容为空,函数将返回True,,否则将返回False
If Trim(txt) = "" Then
Testtxt = False
Else
Testtxt = True
End If
End Function
Public UserName As String
Sub Main()
Dim fLogin As New frmLogin
fLogin.Show vbModal
If Not fLogin.OK Then
'Login Failed so exit app
End
End If
Unload fLogin
Set fMainForm = New frmMain
fMainForm.Show
End Sub
Public Function ConnectString() As String 'returns a DB ConnectString
ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD="
End Function
Public Function ExecuteSQL(ByVal SQL As String,MsgString As String) _
As ADODB.Recordset
'SQL:传递查询语句;MsgString:传递查循信息;自身以一个数据集对象的形式返回
executes SQL and returns Recordset
Dim cnn As ADODB.Connection ‘定义连接
Dim rst As ADODB.Recordset
Dim sTokens() As String ‘定义字符串
On Error GoTo ExecuteSQL_Error ‘异常处理
sTokens = Split(SQL) ‘用Split函数产生一个包涵各个子串的数组
Set cnn = New ADODB.Connection ‘创建连接
cnn.Open ConnectString ‘打开连接
If InStr("INSERT,DELETE,UPDATE",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.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 Testtxt(txt As String) As Boolean ‘判断输入内容是否为空,如果文本框内容为空,函数将返回True,,否则将返回False
If Trim(txt) = "" Then
Testtxt = False
Else
Testtxt = True
End If
End Function