【发布时间】:2016-09-19 00:49:04
【问题描述】:
我正在尝试使用UPDATE 命令更新我的记录。我收到此错误:
没有为一个或多个必需参数指定值。
这是我的代码:
Private Sub saveOle_Click(sender As Object, e As EventArgs) Handles saveOle.Click
Try
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\samplelangtowalangya.mdb;")
conn.Open()
Dim command As New OleDbCommand("UPDATE sample SET ewan = @ewan, ko = @ko, sayo = @sayo, hehehe = @hehehe WHERE Number_of_Employees = @Number_of_Employees", conn)
With command.Parameters
.AddWithValue("@ewan", ewan.Text)
.AddWithValue("@ko", ko.Text)
.AddWithValue("@sayo", sayo.Text)
.AddWithValue("@hehehe", hehehe.Text)
command.ExecuteNonQuery()
End With
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
command.Dispose()
conn.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Number_of_Employees 是我的 ID 和主键。
【问题讨论】:
-
SQL 有 5 个命名参数,而您只提供 4 个。您需要在 where 子句中为命名值提供一个值,否则生成的 SQL 会是什么样子?
-
哦,是的。我试图将
ID放在@ewan之前。我把它放在四个字段之后。现在可以了,谢谢:)