locked
Update Statement syntax error RRS feed

  • Question

  • Hi Everyone !

    I have tried several ways but still couldn't find the error in the below VB code therefore, please help me in finding the solution.

    There might be mistakes in the syntax of the update statement.

    Private Sub updateButton_Click(sender As System.Object, e As System.EventArgs) Handles OkButton.Click

            Try
                If ask() = True Then
                    cmd = New OleDbCommand("UPDATE uinformation SET Ramz = @Ramz,confirmRamz = @confirmRamz," & _
                                           "where UserName = @UserName", cn)
                    cmd.Parameters.AddWithValue("@UserName", UnameTextBox.Text)
                    cmd.Parameters.AddWithValue("@Ramz", NewpassTextBox.Text)
                    cmd.Parameters.AddWithValue("@confirmRamz", CpassTextBox.Text)
                    If cn.State = ConnectionState.Closed Then
                        cn.Open()
                    End If
                    cmd.ExecuteNonQuery()
                    MessageBox.Show("Changes have been made successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    UnameTextBox.Text = ""
                    OldPassTextBox.Text = ""
                    NewpassTextBox.Text = ""
                    CpassTextBox.Text = ""
                Else
                    MessageBox.Show("Incorrect User Name or Password", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End Try
        End Sub

    Thanks


    Nadem

    Friday, September 12, 2014 7:24 AM

Answers

  • Hi Nadem,

    There is a superfluous comma before the WHERE clause.

    Additionally: The OleDb Client doesn't support named parameters, only positional parameters. Only if your are using the Microsoft Access provider you can use them, but the parameters should be ordered too. Try:

    'or "UPDATE uinformation SET Ramz = ?, confirmRamz = ? WHERE UserName = ?;"
    cmd = New OleDbCommand("UPDATE uinformation SET Ramz = @Ramz, confirmRamz = @confirmRamz WHERE UserName = @UserName;", cn)
    cmd.Parameters.AddWithValue("@Ramz", NewpassTextBox.Text)
    cmd.Parameters.AddWithValue("@confirmRamz", CpassTextBox.Text)
    cmd.Parameters.AddWithValue("@UserName", UnameTextBox.Text)
    

    Regards, Elmar

    Friday, September 12, 2014 9:52 AM
  • And a space is missing, but that I wrote already in the never replied thread 

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/d8dcff78-8872-4581-9127-6f31a6104936/update-set-statement-error?forum=vbgeneral#d8dcff78-8872-4581-9127-6f31a6104936

    Please keep your replies in the original thread instead of creating new questions with the same problem.

    "UPDATE uinformation SET Ramz = @Ramz, confirmRamz = @confirmRamz WHERE UserName = @UserName; "


    Success
    Cor


    Friday, September 12, 2014 10:02 AM

All replies

  • Hi Nadem,

    There is a superfluous comma before the WHERE clause.

    Additionally: The OleDb Client doesn't support named parameters, only positional parameters. Only if your are using the Microsoft Access provider you can use them, but the parameters should be ordered too. Try:

    'or "UPDATE uinformation SET Ramz = ?, confirmRamz = ? WHERE UserName = ?;"
    cmd = New OleDbCommand("UPDATE uinformation SET Ramz = @Ramz, confirmRamz = @confirmRamz WHERE UserName = @UserName;", cn)
    cmd.Parameters.AddWithValue("@Ramz", NewpassTextBox.Text)
    cmd.Parameters.AddWithValue("@confirmRamz", CpassTextBox.Text)
    cmd.Parameters.AddWithValue("@UserName", UnameTextBox.Text)
    

    Regards, Elmar

    Friday, September 12, 2014 9:52 AM
  • And a space is missing, but that I wrote already in the never replied thread 

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/d8dcff78-8872-4581-9127-6f31a6104936/update-set-statement-error?forum=vbgeneral#d8dcff78-8872-4581-9127-6f31a6104936

    Please keep your replies in the original thread instead of creating new questions with the same problem.

    "UPDATE uinformation SET Ramz = @Ramz, confirmRamz = @confirmRamz WHERE UserName = @UserName; "


    Success
    Cor


    Friday, September 12, 2014 10:02 AM