c#mysql递增空错误

i86rm4rw  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(371)

我正在更新一个mysql数据库,即使值被设置为0,我也会得到一个奇怪的错误。
我试着运行这个:

MySqlCommand update = new MySqlCommand("UPDATE email_batch SET numberOfSendAttempts = numberOfSendAttempts + 1 AND sentOn = @sentOn WHERE outputFolder = @outputFolder", conn);
update.Parameters.AddWithValue("@sentOn", DateTime.Now);
update.Parameters.AddWithValue("@outputFolder", outputFolder);
update.ExecuteNonQuery();

但我有个错误

Exception has occurred: CLR/MySql.Data.MySqlClient.MySqlException
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll: 'Column 'numberOfSendAttempts' cannot be null'
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at emailBatchReader.emailBatchReader.Main(String[] args) in C:\Users\tpaolini\Desktop\sendEmailBatch\emailBatchReader.cs:line 332

我知道会发生这种情况,因为我将值设置为不为null,但它应该将其设置为递增1。我检查了我的mysql语法,这似乎是正确的,我检查它没有增量语句,它的作品。如果我的语句试图使该值为空,那该怎么办?

syqv5f0l

syqv5f0l1#

您需要使用逗号分隔要设置的字段,而不是 AND ```
UPDATE email_batch
SET numberOfSendAttempts = numberOfSendAttempts + 1, sentOn = @sentOn
WHERE outputFolder = @outputFolder

相关问题