如果帐户出现问题(例如忘记密码),我试图让用户编辑他们的帐户详细信息。 在先前的表单中,用户输入其经过验证的电子邮件,并使用变量来标记记录号,并用于在文本框中显示记录。 如果用户编辑数据并单击“保存”,则一切正常。但是,如果我转到登录表单,我无法使用新凭据登录。
Private Sub ChangeUserDetails_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DataSet1.Users' table. You can move, or remove it, as needed.
Me.UsersTableAdapter.Fill(Me.DataSet1.Users)
AlterUsernameTB.Text = UsersBindingSource(validatedRecord)("Username").ToString
AlterPasswordTB.Text = UsersBindingSource(validatedRecord)("Password").ToString
AlterEmailTB.Text = UsersBindingSource(validatedRecord)("Email").ToString
End Sub
Private Sub SaveBtn_Click(sender As Object, e As EventArgs) Handles SaveBtn.Click
'Exception class will detect errors if any.
Try
Select Case MsgBox("Are you sure you want to alter your account details?", MsgBoxStyle.YesNo, "Are You Sure")
Case MsgBoxResult.Yes
If AlterUsernameTB.Text <> Nothing Then
If AlterPasswordTB.Text <> Nothing Then
If AlterReTypePasswordTB.Text <> Nothing Then
If AlterEmailTB.Text <> Nothing Then
If AlterReTypePasswordTB.Text = AlterPasswordTB.Text Then
'Exception class will detect errors if any.
Me.Validate()
Me.UsersBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DataSet1)
MessageBox.Show("Your account has been altered. Please click on Back to Login.")
Else
MessageBox.Show("Passwords do not match!")
End If
Else
MessageBox.Show("Email textbox is empty!")
End If
Else
MessageBox.Show("Re-type password textbox is empty!")
End If
Else
MessageBox.Show("Password textbox is empty!")
End If
Else
MessageBox.Show("Username textbox is empty!")
End If
Case MsgBoxResult.No
'If 'No' is clicked nothing will happen.
End Select
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
我做错了什么? 任何帮助将不胜感激。
干杯
答案 0 :(得分:0)
我没有将文本框绑定到表并尝试保存它们(这是完全错误的事情),而是在保存之前将代码插入到最后一个If语句中。它有效!
DataSet1.Users(validatedRecord).Username = AlterUsernameTB.Text
DataSet1.Users(validatedRecord).Password = AlterPasswordTB.Text
DataSet1.Users(validatedRecord).Email = AlterEmailTB.Text