Answered by:
Update Statement syntax error

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 SubThanks
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
- Proposed as answer by KareninstructorMVP Friday, September 12, 2014 1:03 PM
- Marked as answer by Franklin ChenMicrosoft employee Monday, September 22, 2014 10:47 AM
Friday, September 12, 2014 9:52 AM -
And a space is missing, but that I wrote already in the never replied thread
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- Edited by Cor Ligthert Friday, September 12, 2014 10:03 AM
- Marked as answer by Franklin ChenMicrosoft employee Monday, September 22, 2014 10:47 AM
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
- Proposed as answer by KareninstructorMVP Friday, September 12, 2014 1:03 PM
- Marked as answer by Franklin ChenMicrosoft employee Monday, September 22, 2014 10:47 AM
Friday, September 12, 2014 9:52 AM -
And a space is missing, but that I wrote already in the never replied thread
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- Edited by Cor Ligthert Friday, September 12, 2014 10:03 AM
- Marked as answer by Franklin ChenMicrosoft employee Monday, September 22, 2014 10:47 AM
Friday, September 12, 2014 10:02 AM