【问题标题】:Syntax error in UPDATE statement access database in vb.net 2010vb.net 2010 中的 UPDATE 语句访问数据库中的语法错误
【发布时间】:2016-04-29 13:23:32
【问题描述】:

我刚刚开始使用 VB.net 几个星期。我想制作一个表单并从文本框中添加数据并更新数据库 (*.accdb) 文件。但我写的代码给出了以下错误:

UPDATE 语句中的语法错误。

Private Sub Button1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button1.Click
    ds6.Clear()
    cmd.Connection = con
    cmd.CommandText = "UPDATE Player SET pid='" + ComboBox3.Text + "', pfn='" _
        + TextBox2.Text + "',pmn='" + TextBox3.Text + "',pln='" + TextBox4.Text _
        + "',nic='" + TextBox5.Text + "',dob='" + DateTimePicker1.Value + "',telm='" _
        + MaskedTextBox1.Text + "',telh='" + MaskedTextBox2.Text + "',addr='" _
        + TextBox6.Text + "',email='" + TextBox10.Text + "',gndr='" + ComboBox1.Text _
        + "',weight='" + TextBox1.Text + "',hight'" + TextBox7.Text + "',sgrlvl'" _
        + TextBox11.Text + "',prate'" + TextBox8.Text + "' bloodg='" & ComboBox2.Text & "'"

    cmd.ExecuteNonQuery()
    MessageBox.Show("Player Updated")

    dssql6 = "select * from Player"
    da6 = New OleDb.OleDbDataAdapter(dssql6, con)
    da6.Fill(ds6, "Player")

    ComboBox1.Text = ("")
    ComboBox2.Text = ("")
    TextBox1.Text = ("")
    TextBox2.Clear()
    TextBox5.Clear()
    TextBox3.Clear()
    TextBox4.Clear()
    TextBox6.Clear()
    TextBox7.Clear()
    TextBox8.Clear()
    TextBox10.Clear()
    TextBox11.Clear()
    MaskedTextBox1.Clear()
    MaskedTextBox2.Clear()

End Sub

结束类

【问题讨论】:

  • 学习使用参数来避免sql注入和格式化问题。
  • 您是否使用相同的信息更新所有行?如果是这种情况,您可能会遇到关键约束。没有 WHERE 子句,你是在插入一个新行吗?如果是这样,您应该使用 INSERT 命令。您也缺少等号。
  • ds6??? da6???这是否意味着您有 六个 数据集和适配器?如果是这样,请停止并重新考虑设计。

标签: .net vb.net


【解决方案1】:

您缺少 hight、sgrlvl 和 prate 的等号。虽然 LarsTech 是对的,但您应该使用参数来做到这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 2013-12-01
    • 1970-01-01
    相关资源
    最近更新 更多