我使用以下代码将数据插入MySQL,但是当我尝试将其插入时会出现错误。
这是我的保存按钮
Private Sub btnsavetreatment_Click(sender As System.Object, e As System.EventArgs) Handles btnsavetreatment.Click
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString =
"server=localhost;userid=root;password=rico;database=god;"
Try
MysqlConn.Open()
COMMAND.CommandText = "INSERT INTO god.treatment (treatmentid,transactiondate,ToothNo,Procedure,AmountCharged,AmountPaid,Balance) values (@treatmentid,@transactiondate,@toothno,@procedure,@amountcharged,@amountpaid,@balance)"
COMMAND.Connection = MysqlConn
COMMAND.CommandType = CommandType.Text
COMMAND.Parameters.AddWithValue("@treatmentid", txttreatmentid.Text)
COMMAND.Parameters.AddWithValue("@transactiondate", dtptransactiondate.Text)
COMMAND.Parameters.AddWithValue("@toothno", txttoothno.Text)
COMMAND.Parameters.AddWithValue("@procedure", txtprocedure.Text)
COMMAND.Parameters.AddWithValue("@amountcharged", txtcharged.Text)
COMMAND.Parameters.AddWithValue("@amountpaid", txtamountpaid.Text)
COMMAND.Parameters.AddWithValue("@balance", txtbalance.Text)
COMMAND.ExecuteNonQuery()
MessageBox.Show("Data Saved")
MysqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
错误消息
您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ Procedure,AmountCharged,AmountPaid,Balance)值(“ 1”,“ Sunday,30 September 20”)附近使用