Private Sub Form_Load() '此段代码的主要作用是当窗体打开时就连接数据库
Dim conn As New ADODB.Connection
Dim connectionstring As String
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" & App.Path & "\DATE.mdbPersist Security Info=False" '数据库路径
conn.Open connectionstring
End Sub
Private Sub Command1_Click()
Static n As Integer
If n >= 3 Then
MsgBox "输入密码次数大于3次,不允许继续登陆"
End
End If
Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0Persist Security Info=FalseData Source=DATE.mdbJet OLEDB:Database Password="
Dim sql As String
Dim rs_login As New ADODB.Recordset
If Trim(Text1.Text) = "" Then '检测用户名正确与否
MsgBox "用户名不能为空,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text1.SetFocus
Else
sql = "select * from 验证 WHERE 用户名='" & Trim(Text1.Text) & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "用户名不存在,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text1 = ""
Text1.SetFocus
Else '检测密码正确与否
If Trim(rs_login.Fields(2)) = Trim(Text2) Then
rs_login.Close
Unload Me
Form2.Show
Else
n = n + 1
MsgBox "第" & n & "次密码错误,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text2.SetFocus
End If
End If
End If
End Sub
Private Sub Command2_Click()
MsgBox "您已成功退出!", vbOKOnly + vbExclamation, "提示"
Unload Me
End Sub
(1)新建数据库并命名为denglu,在该数据库中新建表User1,表包含的列为“ID,username,pwd”。(2)设计登录界面Frmlogin,以及登录成功后要显示的界面Form2,并连接到数据库,使包含在数据库中的合法用户能成功登录该程序,而不合法用户则无法进入程序。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)