Private conn As New ADODB.Connection
Private Sub LoginProcess()
Static j As Integer
Dim rs As New ADODB.Recordset
SQLstr = "select username,password from admin Where username='" & text1.Text & "' and password='" & text2.Text & "'"
Set rs = conn.Execute(SQLstr)
If rs.EOF And rs.BOF Then
j = j + 1
rs.Close
Set rs = Nothing
MsgBox "密码错误"
If j > 2 Then
MsgBox "连续错误3次!程序将退出"
End
End If
Else
rs.Close
Set rs = Nothing
MsgBox "登录成功"
' Form2.Show
Unload Me
End If
End Sub
Private Sub Form_Load()
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Data.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
End Sub
Private Sub btLogin_Click()
Call LoginProcess
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set conn = Nothing
End Sub
Private Sub text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Call LoginProcess
End Sub
'其中data.mdb是存放账号和密码的数据库文件,本例子采用的是Access数据库。