更改密码的按钮代码改为:
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
不过还是建议不要自己做的。