suchanoob
suchanoob

Reputation: 300

VB.NET: SQL Parameters (Update)

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.

Upvotes: 0

Views: 2742

Answers (1)

sallushan
sallushan

Reputation: 1147

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

Upvotes: 1

Related Questions