当前位置:编程学习 > VB >>

vb登录程序,请高手帮忙分析,谢谢!

Option Explicit
Dim cnt As Integer '记录确定次数

Private Sub Command1_Click()
Dim sql As String
Dim rs_login As New ADODB.Recordset
If Trim(txtuser.Text) = "" Then '判断输入的用户名是否为空
MsgBox "没有这个用户", vbOKOnly + vbExclamation, ""
txtuser.SetFocus
Else
sql = "select * from 密码表 where 用户名='" & txtuser.Text & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "没有这个用户", vbOKOnly + vbExclamation, ""
txtuser.SetFocus
Else '检验密码是否正确
If Trim(rs_login.Fields(1)) = Trim(txtpwd.Text) Then
userID = txtuser.Text
userpow = rs_login.Fields(2)
rs_login.Close
Unload Me
MDIForm1.Show
Else
MsgBox "密码不正确", vbOKOnly + vbExclamation, ""
txtpwd.SetFocus
End If
End If
End If
cnt = cnt + 1
If cnt = 3 Then
Unload Me
End If
Exit Sub
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub login_Load()
Dim connectionstring As String
conn = "provider=Microsoft.Jet.oledb.4.0;" & _
"data source=book.mdb"
connectionstring.Open connectionstring
cnt = 0
End Sub

此段代码需要实现以下功能:1.与access数据库的密码表的用户密码对比,若相同,则出现MDIForm1窗体。

2.登录三次错误,则自动关闭窗体。

3.当然,窗体上有好几个控件的,相信高手明白的...

4.跪求高手帮忙,感激涕零!!

补充:ACCESS数据库应该也是可以用SQL的查询语句的...555,等待vb强人帮忙解决
		
追问:建立了access数据库了,用户密码都有的。而且用ado控件测试连接也成功了...
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,