【发布时间】:2015-03-25 12:19:47
【问题描述】:
connect()
MD = "update EmpRec set ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "', '" & TextBox4.Text & "', '" & TextBox5.Text & "','" & ComboBox2.Text & "','" & ComboBox3.Text & "','" & Label3.Text & "','" & ComboBox4.Text & "','" & ComboBox5.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & Label19.Text & "','" & Label22.Text & "','" & Label25.Text & "','" & TextBox6.Text & "','" & TextBox10.Text & "')"
comm = New OleDbCommand(MD, conn)
comm.ExecuteNonQuery()
MsgBox("Done!", MsgBoxStyle.Information)
grid()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
DataGridView1.Refresh()
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
End Sub
【问题讨论】:
-
您真的需要将其更改为parameterized query,然后如果您仍然存在任何问题,请重新访问。
-
你有什么错误吗?
-
您不能在任何已发布的 VS 中使用该命令,也不能针对我所知道的任何数据库系统使用该命令。请look at the correct syntax,然后停下来研究一下Sql Injection是什么
-
您将值传递给您的 SQL,但没有告诉 UPDATE 要设置哪些列。此外,您正在输出“完成!”给用户,而无需实际检查是否已完成任何操作。正如 Alex K 指出的那样,您的查询中缺少参数已经够糟糕的了,但是您确实需要在其中进行一些错误处理。至少,把它放在一个 Try Catch 中。你知道什么比参数化查询更好吗?一个不错的存储过程。那不是很可爱吗?我个人喜欢一个好的存储过程。
标签: sql vb.net visual-studio-2012