「SQL ステートメントの末尾にセミコロン (;) がありません」という OleDbException が発生しました。UPDATEステートメントが正しいかどうか混乱しました。私のコードでは、ボタンを使用して update ステートメントをテストしています。誰でも私を助けることができますか?変数の値を増やすために、変数に 1 を追加します。ボトルの数。Microsoft Access データベースを使用しています。プライマリ ID は ID で、ユニークは room_number です。
これは私のコードです:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'====test number of bottles=============
Dim bottlecount As Integer 'variable used in order to increase the value of no. of bottle/s used
bottlecount = Form3.lblBottle.Text
bottlecount += 1
Form3.lblBottle.Text = bottlecount
roomhold = 1
Dim statement As String = "UPDATE tblPatientInfo SET bottle_used='" & bottlecount & "' WHERE room_number= '" & roomhold & "' ORDER BY ID ;"
Dim cmd As New OleDbCommand
With cmd
.CommandText = statement
.Connection = Conn
Conn.Open()
.ExecuteNonQuery()
End With
Conn.Close()
End Sub
===変更を適用した後========== これは私のコードです:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bottlecount As Integer = CInt(Form3.lblBottle.Text) + 1
Form3.lblBottle.Text = bottlecount
roomhold = 1
Dim statement As String = "UPDATE tblPatientInfo SET bottle_used = @bottlecount"
statement &= "WHERE room_number = @roomhold"
Dim cmd As New OleDbCommand
With cmd
.Connection = Conn
.CommandType = CommandType.Text
.CommandText = statement
.Parameters.AddWithValue("@bottlecount", bottlecount)
.Parameters.AddWithValue("@roomhold", roomhold)
Conn.Open()
.ExecuteNonQuery()
End With
Conn.Close()
どんな助けでも大歓迎です。ありがとう!