以文本方式查看主题

-  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=43991)

--  作者:策动中国
--  发布时间:2013/12/20 11:05:00
--  自定义用户密码修改出错

Dim UserName As String = e.Form.Controls("UserName").Value
Dim UserGroup As String = e.Form.Controls("UserGroup").Value
Dim PassWord As String = e.Form.Controls("PassWord").Value
Dim OldUserName As String
Dim dt As DataTable
Dim dr As DataRow
Dim cmd As New SQLCommand
Dim Parts() As String = e.Form.Text.Split("-")
OldUserName = Parts(Parts.Length -1)
cmd.C
cmd.CommandText = "Select * From {Users} Where [Name] = \'" & UserName & "\'"
dt = cmd.ExecuteReader
dr = dt.DataRows(0)
If e.Form.Controls("OldPassWord").Value = dr("Password") Then
cmd.CommandText = "Update {Users} Set [Name] = \'" & UserName & "\',[Group] = \'" & UserGroup
cmd.CommandText = cmd.CommandText & "\', [Password] = \'" & Password & "\' Where [Name]= \'" & OldUserName & "\'"
 If cmd.ExecuteNonQuery = 1 Then \'返回1表示更改成功
  Messagebox.show("密码更改成功,切记新设密码!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If
Else
    Messagebox.show("老密码错误,更改失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

请问专家这代码哪出错了,老是不执行新密码写入,急急


--  作者:Bin
--  发布时间:2013/12/20 11:07:00
--  
同一个问题不要重复提问两次,类似这样的问题最好能上个例子.


或者你自己先用这个方法:
http://www.foxtable.com/help/topics/1485.htm

先找出是哪一行出错,然后分析原因,搞不定,贴出代码,并告诉我们运行到哪一行出错,以及错误提示。

--  作者:策动中国
--  发布时间:2013/12/20 11:47:00
--  

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:无法更改自定议密码.rar

 

怎么也执行不了新密码更改,本人为初学者,找不出代码哪里错了,还请专家帮忙啊


--  作者:Bin
--  发布时间:2013/12/20 11:49:00
--  

新手,一般没有必要自定义用户管理了,因为2013版内置的用户管理,也可以基于外部表了:

http://www.foxtable.com/help/topics/2723.htm

还可以自定义登陆窗口:

http://www.foxtable.com/help/topics/2729.htm

 

就是老鸟,自己写用户管理的也不多了。


--  作者:狐狸爸爸
--  发布时间:2013/12/20 12:42:00
--  

更改密码的按钮代码改为:

 

Dim UserName As String = e.Form.Controls("UserName").Value
Dim UserGroup As String = e.Form.Controls("UserGroup").Value
Dim PassWord As String = e.Form.Controls("PassWord").Value
Dim OldPassord As String
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "Select [Password] From {Users} Where [Name] = \'" & UserName & "\'"
OldPassord  = cmd.ExecuteScalar
If OldPassord = e.Form.Controls("OldPassWord").Value  Then
    cmd.CommandText = "Update {Users}  Set [Password] = \'" & Password & "\' Where [Name]= \'" & UserName & "\'"
    If cmd.ExecuteNonQuery = 1 Then \'返回1表示更改成功
        Messagebox.show("密码更改成功,切记新设密码!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    End If
Else
    Messagebox.show("老密码错误,更改失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

不过还是建议不要自己做的。