• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

Change Password SQL Error on Windows Form App

I'm trying to make a function where the user can change their password.  I have written the following code but kep getting an error 'OleDbException was unhandled' ' Syntax error in UPDATE statement'.

Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database.accdb")
        Dim cmd As OleDbCommand = New OleDbCommand("UPDATE UserTable SET Password='" & TextBox2.Text & "' WHERE UserID='" & "'Module1.currentUser'", con)
        con.Open()


        Dim affectRow As Integer = cmd.ExecuteNonQuery()

        If affectRow <> 0 Then
            MessageBox.Show("Password changed successfully!")
            MainMenu.Show()
            Me.Close()

        End If

Can anyone solve the error?
0
koldjg
Asked:
koldjg
  • 2
  • 2
1 Solution
 
mvgeertruyenCommented:
Change

WHERE UserID='" & "'Module1.currentUser'", con)

to

WHERE UserID='" & Module1.currentUser & """, con)

0
 
koldjgAuthor Commented:
I still get the same error.  Heres a screenshot

http://img4.imageshack.us/img4/9963/screenshotbhn.jpg 
0
 
mvgeertruyenCommented:
In SQL this should work - you can try to enclose userid and password between brackets; they might be reserved words.
"UPDATE UserTable SET [Password]='" & TextBox2.Text & "' WHERE [UserID]='" & Module1.currentUser & """
Copy to error to the cliboard and see if it give more information about the syntax.

rgds

0
 
koldjgAuthor Commented:
Yes that worked, thanks a lot for your help.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now