Change Password SQL Error on Windows Form App

Posted on 2009-04-20
Last Modified: 2013-12-25
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)

        Dim affectRow As Integer = cmd.ExecuteNonQuery()

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

        End If

Can anyone solve the error?
Question by:koldjg
    LVL 6

    Expert Comment


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


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


    Author Comment

    I still get the same error.  Heres a screenshot
    LVL 6

    Accepted Solution

    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.



    Author Comment

    Yes that worked, thanks a lot for your help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now