(编辑为使用 MySQL 特定对象而不是通用 ODBC)
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