-- 作者:策动中国
-- 发布时间: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
请问专家这代码哪出错了,老是不执行新密码写入,急急
|
-- 作者:狐狸爸爸
-- 发布时间: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
不过还是建议不要自己做的。
|