在测试如何通过单击按钮更新最新数据库条目中的特定列时出现此错误。之前,我将更新语句设置为
Dim statement As String = "UPDATE tblPatientInfo SET bottle_used = @bottlecount"
statement &=" WHERE room_number =1"
但是数据库中的所有条目都已更新,这就是我尝试使用 ORDER BY ID DESC 的原因,ID 是主 ID。该程序应该获取最新的数据库条目,它只会更新bottle_used。使用它时,我得到了一个 OleDbException。
这是我的代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'====test number of bottles=============
Form5.lblBottle.Text = Form5.lblBottle.Text + 1
Dim statement As String = "UPDATE tblPatientInfo SET bottle_used = @bottlecount ORDER BY ID DESC"
Dim cmd As New OleDbCommand
With cmd
.Connection = Conn
.CommandType = CommandType.Text
.CommandText = statement
.Parameters.AddWithValue("@bottlecount", Form5.lblBottle.Text)
Conn.Open()
.ExecuteNonQuery()
End With
Conn.Close()
End Sub
任何帮助,将不胜感激。谢谢!