sql - 如何在 Access 数据库中为我的投票系统添加 1 我的 SQL 错误

标签 sql vb.net

如何在 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/

相关文章:

sql - 数据类型tinyint 的算术溢出错误,值= -1

sql - 删除 SELECT 语句中的最后一个逗号

.net - 检测 RichTextBox 中的图像

sql - 在 VB NET 中从 SQL 数据库中检索位列

vb.net - 如何在 vb.net 2003 中读取 excel 文件

mysql - 批量 INSERT INTO mySQL 或 none insert none 如果有错误 VB.Net

mysql - 高效查询、表桥/索引和结构

sql - 如何构造涉及最大值的 SQL 查询?

mysql - 插入/更新 MySql 数据库的函数返回错误的 "affected rows"数字