如何在 Access 数据库中为我的投票系统添加 1。
当前代码如下:
Dim sql as string = "UPDATE president SET votes = '" &1& "' WHERE Student = '"&listbox1.text&"'"
最佳答案
Using...End using
block 确保您的数据库对象已关闭并处置。
始终使用参数使sql字符串更容易编写并避免Sql注入(inject)。
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
关于sql - 如何在 Access 数据库中为我的投票系统添加 1 我的 SQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60703574/