Hello everyone,
I have been coding a Reset Login Details form, the user needs to enter the new Username, the new Password and the Current Password.
Here is my code below - something in the form is not working as i am getting an error when i fill in the form about the INSERT INTO statement.
Imports System.Data.OleDb
Public Class frmChangeLoginDetails
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim con As OleDb.OleDbConnection
Dim cmd2, mystr As String
mystr = ("Provider=Microsoft.JET.OLEDB.4.0;" & _
"Data Source=|DataDirectory|\PsychologicalStateTracker.mdb")
con = New OleDb.OleDbConnection(mystr)
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand( _
"SELECT * FROM tblLogin WHERE Password = '" & txtCurrentPassword.Text & "'", con)
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
If (sdr.Read() = True) Then
cmd2 = "INSERT INTO tblLogin (Username,Password) values ('" & txtNewUsername.Text & "','" & txtNewPassword.Text & "')"
Dim run = New OleDb.OleDbCommand
Try
run = New OleDbCommand(cmd2, con)
run.ExecuteNonQuery()
MsgBox("The Username and Password have been changed succesfully.")
con.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
End Try
Else
MessageBox.Show("Invalid current password!")
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
frmLogin.Show()
Me.Hide()
End Sub
End Class