1

I am a beginner at databases with VB.Net and am trying to update a password (field) in a database and I keep getting an error:

"Syntax error in query expression '((UID = ?) AND ((? = 1 AND Username IS NULL) OR (Username = ?)) AND ((? = 1 AND Firstname} IS NULL) OR (Firstname} = ?)) AND ((? = 1 AND Surname IS NULL) OR (Surname = ?)) AND ((? = 1 AND UPassword IS NULL) OR (UPassword = ?)) AND ((? = 1 AND DOB IS NULL)'."

Here is the code for the form it corresponds to and happens when the reset button is clicked.

Public Class ResetPW
    Dim con As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim sql As String
    Dim dbProvider As String
    Dim dbSource As String
    Dim da As New OleDb.OleDbDataAdapter

    Private Sub cbxShowchar_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxShowchar.CheckedChanged
        If cbxShowchar.Checked = True Then
            txtNewpassword.PasswordChar = ""
            txtVNewpassword.PasswordChar = ""
        Else
            txtNewpassword.PasswordChar = "*"
            txtVNewpassword.PasswordChar = "*"
        End If
    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        Me.Close()
        Form2.Show()
    End Sub

    Private Sub ResetPW_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
        dbSource = "DATA Source = C:\Users\Luke\Dropbox\FdSc Computing\Year 2\Project\Product\Book Database.accdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        sql = "SELECT * FROM T_Users"
        da = New OleDb.OleDbDataAdapter(Sql, con)
        da.Fill(ds, "Users")
        MsgBox("The database is now open")
        con.Close()
        MsgBox("The database is now closed")
    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        If txtNewpassword.Text = txtVNewpassword.Text Then
            Dim cb As New OleDb.OleDbCommandBuilder(da)
            ds.Tables("Users").Rows(0).Item(4) = txtNewpassword.Text
            da.Update(ds, "Users")                      'ERROR HAPPENS HERE'
            MsgBox("Password Reset", vbInformation)
        Else
            MsgBox("The passwords do not match", vbExclamation)
        End If
    End Sub
End Class

I would be very grateful for any help. Thanks guys!

3
  • FirstName} is this really the field name? Commented Sep 12, 2013 at 12:58
  • HaHa silly me I was trying things such as adding curly brackets etc and when reverting back forgot to remove that one, the last thing I changed was removing spaces in field names and now works so must of been that. Commented Sep 12, 2013 at 13:04
  • Possible duplicate of OleDbCommandBuilder creates SQL statements that result in "syntax error" Commented Nov 9, 2015 at 18:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.