View Full Version : Syntax error in UPDATE statement.

01-15-2012, 02:45 PM
I have this error when I run this code:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Passwords.accdb"

Dim SqlString As String = "Update [Pass] Set UserName = ?, Password = ?"

Using conn As New OleDb.OleDbConnection(ConnString)

Using cmd As New OleDb.OleDbCommand(SqlString, conn)

cmd.CommandType = CommandType.Text

cmd.Parameters.AddWithValue("UserName", TextBox1.Text)

cmd.Parameters.AddWithValue("Password", TextBox2.Text)



End Using

End Using
End Sub
End Class

I am a newbbie in xthis field so I will provide you details of the access database:

Database name: Passwords.accdb
Table name: Pass : Table
Fields in the table name: UserName and Password
I also uploaded a printscreen with my form

Any suggestions are very welcomed......
Thank you!

01-19-2012, 12:16 PM
You didn't given the error which thrown during execution.

Try this, instead of using parameters, supply the values directly in the query and execute.
Like this
Dim SqlString As String = "Update [Pass] Set UserName = '"+TextBox1.Text+"', Password = '" + TextBox2.Text + '"

Make sure that the both text boxes are not null.