-5
var insertDate = DateTime.Now

我打开了 Windows 应用程序,25/07/2013但在29/07/2013.

在数据库中,25/07/2013存储而不是29/07/2013.

请建议我为什么?

提前致谢。

普拉萨德

4

2 回答 2

3

是的。您需要在将值写入数据库之前设置您的 insertDate。

insertDate = DateTime.Now;
// write to database
于 2013-07-29T13:54:33.707 回答
1

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.

于 2013-07-29T14:05:16.397 回答