SQL 数据库课程设计学生成绩系统
End Sub
确定按钮(cmdOk)处理程序(Click)
Private Sub cmdOk_Click() Dim s1 As String
Dim Password As String
On Error Resume Next
If Text1.Text = "" Then ‘用户名为空,则退出 MsgBox ("用户名不能为空,请重新输入") Text1.SetFocus Exit Sub
End If
‘按输入的用户名进行查询 s1 = "SELECT * from 用户表 WHERE 用户名='" & Text1.Text & "'" Adodc1.RecordSource = s1 Adodc1.Refresh
If Adodc1.Recordset.EOF = False Then ‘判断查询结果 UserName = Adodc1.Recordset.Fields(0) ‘有该用户名,即用户名正确 Password = Adodc1.Recordset.Fields(1) UserType = Adodc1.Recordset.Fields(2)
If Password = Text2.Text Then ‘判断密码是否正确
Unload Me ‘密码正确,关闭当前窗体 FrmMain.Show ‘显示主界面窗体 Exit Sub Else
MsgBox ("密码错误,请重新输入") ‘密码错误,提示 Text2.SetFocus Text2.Text = "" End If
Else ‘没有该用户名,即用户名错误 MsgBox "用户名错误,请重新输入" Text1.SetFocus Text1.Text = "" Text2.Text = "" End If
Count1 = Count1 + 1 ‘错误次数累计 If Count1 >= 3 Then
MsgBox "错误超过3次,系统退出" Unload Me End If End Sub