以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  提取自定义用户密码出错  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=28119)

--  作者:zcw728909
--  发布时间:2013/1/19 15:25:00
--  提取自定义用户密码出错

在自定义菜单有个标准按钮“生产修改”,想要实现在单击它时先输入密码才能打开相应的窗口,密码就是当前登录用户的登录密码(根据帮助做的自定义用户),单击事件的代码:

If e.Button.Name="生产修改" Then
    Dim psd As String
    Dim dr As DataRow = DataTables("Users").Find("Name = \'" & UserName & "\'")
    InputValue(psd,"验证","请输入密码")
    If psd = dr("Password") Then
        Forms("生产修改").Open()
    Else
        Messagebox.Show("密码错误","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    End If
End If

可是在输完密码点击确定后却出现下面的报错,是怎么回事?

 


图片点击可在新窗口打开查看此主题相关图片如下:00000.jpg
图片点击可在新窗口打开查看

--  作者:lin_hailun
--  发布时间:2013/1/19 15:34:00
--  
代码改一下


If e.Button.Name="生产修改" Then
    Dim psd As String
    Dim dr As DataRow = DataTables("Users").Find("Name = \'" & UserName & "\'")
    If dr Is Nothing Then
        msgbox("不存在这个用户")
    Else
        InputValue(psd,"验证","请输入密码")
        If psd = dr("Password") Then
            Forms("生产修改").Open()
        Else
            Messagebox.Show("密码错误","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If
    End If
End If

--  作者:zcw728909
--  发布时间:2013/1/19 15:47:00
--  
以下是引用lin_hailun在2013-1-19 15:34:00的发言:
代码改一下


If e.Button.Name="生产修改" Then
    Dim psd As String
    Dim dr As DataRow = DataTables("Users").Find("Name = \'" & UserName & "\'")
    If dr Is Nothing Then
        msgbox("不存在这个用户")
    Else
        InputValue(psd,"验证","请输入密码")
        If psd = dr("Password") Then
            Forms("生产修改").Open()
        Else
            Messagebox.Show("密码错误","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If
    End If
End If

谢谢了,用你的代码试了一下,结果直接弹出对话框:不存在这个用户。

后来仔细检查才发现原来是引用的登录用户名错了,应该为:

Dim dr As DataRow = DataTables("Users").Find("Name = \'" & _UserName & "\'")