(一般的な ODBC ではなく、MySQL 固有のオブジェクトを使用するように編集されています)
Dim bn As String = "" ' Set this to some value in your code
Dim bottles As Integer = 0 ' Set this to some value in your code
Dim SQLStatement As String = "UPDATE patient SET number_of_bottles = @bottles WHERE bednumber = @bednumber"
Using cnn As New MySqlConnection("Connection string here")
Dim cmd As New MySqlCommand(SQLStatement, cnn)
cmd.Parameters.AddWithValue("bottles", bottles)
cmd.Parameters.AddWithValue("bednumber", bn)
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
End Using
手動でオブジェクトを作成する代替バージョンMySqlParameter
-- パラメータ オブジェクトを作成し、それらの値を設定してから、MySqlCommand
オブジェクトのパラメータ コレクションに追加する必要があることに注意してください。
Using cnn As New MySqlConnection("Connection string here")
Dim cmd As New MySqlCommand(SQLStatement, cnn)
Dim pBottles As New MySqlParameter("bottles", bottles)
Dim pBedNumber As New MySqlParameter("bednumber", bn)
cmd.Parameters.Add(pBottles)
cmd.Parameters.Add(pBedNumber)
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
End Using