简体   繁体   中英

Operand type clash: int is incompatible with date when I am trying to update my database

I am running this query for updating the datetime column in my table:

DateTime today = DateTime.Today;
string[] queries = new string[] { "UPDATE *** SET ExpirationDate = " + today.ToString("yyyy/MM/dd"),
"UPDATE *** SET WrittenDate = " + today.ToString("yyyy/MM/dd"),
"UPDATE *** SET SystemDate = " + today.ToString("yyyy/MM/dd"),
"UPDATE *** SET SystemDate = " + today.ToString("yyyy/MM/dd"),
"UPDATE *** SET EventDate = " + today.ToString("yyyy/MM/dd")};

This format is based off of what I found in this thread: Operand type clash: int is incompatible with date + The INSERT statement conflicted with the FOREIGN KEY constraint

But it is not working. I know that they are datetime fields because I can successfully perform DATEADDs on them. I just want to set all the records in these columns to the current date, but I keep getting the same error even with all the different ways I've tried. Advance thanks for any help!

The DATE Value in SQL must be placed in single quotes '

I am running this query for updating the datetime column in my table:

DateTime today = DateTime.Today;
string[] queries = new string[] { "UPDATE *** SET ExpirationDate = '" + today.ToString("yyyy/MM/dd") + "'",
"UPDATE *** SET WrittenDate = '" + today.ToString("yyyy/MM/dd") + "'",
"UPDATE *** SET SystemDate = '" + today.ToString("yyyy/MM/dd") + "'",
"UPDATE *** SET SystemDate = '" + today.ToString("yyyy/MM/dd") + "'",
"UPDATE *** SET EventDate = '" + today.ToString("yyyy/MM/dd") + "'"};

I am not sure about the "yyyy/MM/dd", I guess you should place it "yyyyMMdd".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM