var insertDate = DateTime.Now
我打开了 Windows 应用程序,25/07/2013
但在29/07/2013
.
在数据库中,25/07/2013
存储而不是29/07/2013
.
请建议我为什么?
提前致谢。
普拉萨德
是的。您需要在将值写入数据库之前设置您的 insertDate。
insertDate = DateTime.Now;
// write to database
The line of code
var insertDate = DateTime.Now;
doesn't "bind" that value to "the current time" so that it is "always up-to-date" but it sets the value of that variable insertDate
to the date/time at the instant of execution.
So like Derek already said, set this variable just before you perform the insert.