How can I add 1 for my voting system in access database my SQL is wrong

Viewed 48

How can I add 1 for my voting system in access database.

Current code below:

Dim sql as string = "UPDATE president SET votes = '" &1& "' WHERE Student = '"&listbox1.text&"'"
1 Answers

Using...End Using blocks ensure that your database objects are closed and disposed.

Always use parameters to make sql string easier to write and avoid Sql injection.

Private Sub OpCode()
    Using cn As New OleDbConnection("Your connection string"),
            cmd As New OleDbCommand("Update president SET votes = votes + 1 WHERE Student = @Student;")
        cmd.Parameters.Add("@Student", OleDbType.VarChar).Value = ListBox1.Text
        cn.Open()
        cmd.ExecuteNonQuery()
    End Using
End Sub
Related