标题:求助 设计用户登录 密码没错 老是显示密码错误
取消只看楼主
ruoyufan
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-4-14
结帖率:0
已结贴  问题点数:20 回复次数:1 
求助 设计用户登录 密码没错 老是显示密码错误
Private Sub cmdOK_Click()

txtUserName.Text = Trim(txtUserName.Text)
If txtUserName.Text = "" Then
   MsgBox " 请输入用户名!"
   Exit Sub
End If

txtPassword.Text = Trim(txtPassword.Text)
If txtPassword.Text = "" Then
   MsgBox " 请输入密码!"
   Exit Sub
End If

Dim msg, style, title, response

Dim Conn As New ADODB.Connection     '声明并实例化连接数据库对象 -- 用来连接数据库文件,并对数据库以及数据表的操作
Dim Rst As New ADODB.Recordset       '声明并实例化数据记录集对象 -- 用来返回数据记录集,并对记录的操作

'执行 ADODB.Connection对象的Open方法,完成数据库的连接
Conn.Open SQLConnecTionString1

'执行 ADODB.Recordset对象的Open方法,获得记录集
Rst.Open "Select * From 用户 Where 用户名='" & txtUserName.Text & "'", Conn, adOpenKeyset, adLockPessimistic
If Not (Rst.RecordCount >= 1) Then
   MsgBox "数据表记录为0!"
   End
End If

If Not (Rst.EOF And Rst.BOF) Then
   '检查正确的密码
   If Rst.Fields("密码") = txtPassword.Text Then
      Unload Me
      Form1.Show
   Else
      msg = "错误的登录密码!" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
      style = vbRetryCancel + vbExclamation + vbDefaultButton1
      title = "提示"
      response = MsgBox(msg, style, title)
      If response = vbRetry Then
         Exit Sub
      ElseIf response = vbCancel Then
         End
      End If
   End If
Else
   msg = "错误的用户名!" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
      style = vbRetryCancel + vbExclamation + vbDefaultButton1
      title = "提示"
      response = MsgBox(msg, style, title)
      If response = vbRetry Then
         Exit Sub
      ElseIf response = vbCancel Then
         End
      End If
End If

End Sub
搜索更多相关主题的帖子: 连接数据库 用户登录 输入密码 用户名 数据表 
2015-04-14 19:00
ruoyufan
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-4-14
得分:0 
新人求帮助
2015-04-14 19:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-443992-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.255785 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved