学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
 11 12
发新话题
打印

请高手帮忙看一下,纠错!

请高手帮忙看一下,纠错!

登录窗体,利用adodc控件从access数据库的“用户管理”表检查用户名称和登录密码,两个文本名是txtUserName和txtPassword运行过程有问题,请大家纠错,谢谢!
Option Explicit
Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()
    '设置全局变量为 false
    '不提示失败的登录
    LoginSucceeded = False
    Me.Hide
End Sub

Private Sub cmdOK_Click()
      If Trim(txtUserName.Text) = "" Then
        MsgBox "用户名不能为空", vbExclamation + vbOKOnly, "提醒"
        txtUserName.SetFocus
        Exit Sub
    End If

    If Trim(txtPassword.Text) = "" Then
        MsgBox "用户密码不能为空", vbOKOnly, "提醒"
        txtPassword.SetFocus
        Exit Sub
    End If
   
    If Not IsNumeric(txtPassword.Text) Then
        MsgBox "密码必须为数字", vbExclamation + vbOKOnly, "提醒"
        txtPassword.SelStart = 0
        txtPassword.SelLength = Len(txtPassword)
        txtPassword.SetFocus
        Exit Sub
     End If
     
     Adodc1.RecordSource = "select * from 用户管理   where 用户名称= '" & txtUserName.Text & "'"
     Adodc1.Refresh
     With Adodc1.Recordset
        If txtUserName.Text <> Adodc1.Recordset.Fields("用户名称").Value Then
                MsgBox "用户名错误,请重新输入"
                txtUserName.SetFocus
                Exit Sub
        ElseIf txtPassword.Text <> Adodc1.Recordset.Fields("登录密码").Value Then
                MsgBox "密码错误,请重新输入"
                txtPassword.SetFocus
                Exit Sub
       Else
            MDIForm1.Show
       End If
      
  End With
    Exit Sub

End Sub

TOP

既然使用了with Adodc1.Recordset,那么中间有Adodc1.Recordset就可以不用写了.

TOP

回楼上,不是该问题

补充:执行时弹出“adodc1”的对话框,提示from子句语法错误。点确定,又出现“实时错误.......对象 'refresh'的方法'iadodc'失败”

TOP

"select * from 用户管理   where 用户名称= '" & txtUserName.Text & "'"
是不是这句话有问题...我没怎么看vb,所以不一定对..字符串连接+就可以了吧.
学习需要安静。。海盗要重新来过。。

TOP

你这里用 with Adodc1.Recordset 根本就没一点用处  !
我看你干脆用ADODC控件绑定你的那数据库表。。更加简单!

TOP

Adodc1.RecordSource = "select * from 用户管理   where 用户名称= '" & txtUserName.Text & "'"
     Adodc1.Refresh
     With Adodc1.Recordset
        If txtUserName.Text <> Adodc1.Recordset.Fields("用户名称").Value Then
                MsgBox "用户名错误,请重新输入"
                txtUserName.SetFocus
                Exit Sub
        ElseIf txtPassword.Text <> Adodc1.Recordset.Fields("登录密码").Value Then
                MsgBox "密码错误,请重新输入"
                txtPassword.SetFocus
                Exit Sub
       Else
            MDIForm1.Show
       End If
      
  End With
这段代码 逻辑相当混乱!
正常的思路:
1.首先查数据库里是否存有数据
2.其次查找用户名,
  其中有两中方法:
   1.从数据中,从第一条查到起
   2.直接查,看返回值是否为空
3.再查与之匹配的密码
按照,这样下去就不会出错啦!

TOP

那这组呢,也有错误

Private Sub Command1_Click()
Adodc1.RecordSource = "select *from 用户表 where 用户名称='" & Text1.Text & "'"
Do While Not Adodc1.Recordset.EOF
If Text1.Text = Adodc1.Recordset.Fields("用户名称") Then
Me.Hide
Form2.Show
Else
  MsgBox "输入错误!"
End If
Adodc1.Recordset.MoveNext
Loop
End Sub

TOP

那我问你,有没设置adodc1.datasource?

TOP

回楼上

没有,不知道再哪设?设adodc1的吗?

TOP

喜欢用ado,不喜欢用控件
-------------程序*酒*人生

TOP

 11 12
发新话题