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!
FirstName}is this really the field name?