我正在运行此查询以更新表中的datetime列:
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")};
此格式基于我在此线程中发现的内容: Operand type clash: int is incompatible with date + The INSERT statement conflicted with the FOREIGN KEY constraint
但是它不起作用。我知道它们是日期时间字段,因为我可以对它们成功执行DATEADD。我只想将这些列中的所有记录设置为当前日期,但是即使尝试了所有不同的方法,我仍然会遇到相同的错误。预先感谢您的帮助!
答案 0 :(得分:0)
SQL中的DATE值必须放在单引号'
中我正在运行此查询以更新表中的datetime列:
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") + "'"};
我不确定“ yyyy / MM / dd”,我猜应该将其放置为“ yyyyMMdd”。