黄河鑫业公司领导班子:VB验证登陆的代码

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 03:19:41
只能验证第一个用户,别的用户都不能登陆

代码如下:
Private Sub Command1_Click()
Adodc1.Refresh
If Adodc1.Recordset.EOF = True Then
MsgBox "用户表为空,请添加用户"
adduser.Show
Exit Sub
End If
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
If Text1.Text = Adodc1.Recordset.Fields("name").Value And Text2.Text = Adodc1.Recordset.Fields("pwd").Value Then
Unload Me
Mainform.Show
Exit Sub
Else
If Trim(Text1.Text) = "" Or Trim(Text2.Text) = "" Then
MsgBox "用户名或密码为空,请重试"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Else
MsgBox "用户名或密码不匹配,请重试"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End If
End If
Adodc1.Recordset.MoveNext
Loop
End Sub

Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
If Text1.Text = Adodc1.Recordset.Fields("name").Value And Text2.Text = Adodc1.Recordset.Fields("pwd").Value Then
Unload Me
Mainform.Show
Exit Sub
Else
以上代码只检查了第一个记录,需要一个for循环,
循环中加Adodc1.Recordset.Movenext然后继续比较。
这样的话可以实现,但是比较烦琐,如果记录太多,浪费时间,
建议根据输入的用户名和密码到表里去查询是否有该记录,如果有而且密码正确,则可以进入系统,否则提示错误信息。我觉得这样简单些,处理起来速度也快。
我的QQ37191520,一起讨论VB吧