0

I'm trying to update some values but it seems that there is a problem with my code.

Dim con As New OleDbConnection

Dim id As Integer = Main.Passes.Items.Count + 1

    Try
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= ...\database.mdb"
        con.Open()
    Catch ex As Exception
        MsgBox("There was a problem connection to database.", MsgBoxStyle.Critical)
    End Try

    Dim objCmd As OleDbCommand
    Dim strSQL As String

    strSQL = "UPDATE passwords SET website= @website, username= @username, password= @password, dates= @datenow, notes= @notes WHERE id= @id"
    objCmd = New System.Data.OleDb.OleDbCommand(strSQL, con)

    objCmd.Parameters.AddWithValue("@website", txtURL.Text)
    objCmd.Parameters.AddWithValue("@username", txtUser.Text)
    objCmd.Parameters.AddWithValue("@password", txtPass.Text)
    objCmd.Parameters.AddWithValue("@datenow", txtDate.Text)
    objCmd.Parameters.AddWithValue("@notes", txtNotes.Text)
    objCmd.Parameters.AddWithValue("@id", id)

    objCmd.ExecuteNonQuery()
    con.Close()

The error I get is: Syntax error in UPDATE statement.

1 Answer 1

1

Try enclose your column names in `` (backticks). I guess password column is the culprit, probably a keyword.

Sign up to request clarification or add additional context in comments.

2 Comments

You mean like this? strSQL = "UPDATE passwords SET website= @website, username= @username, password= @password, dates= @datenow, notes= @notes WHERE id= @id" Did it. I don't get any error but I get no result as well.
No. It just worked. There was a problem with the id. Thanks a ton!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.