【问题标题】:How to insert current time to a database as a datetime object?如何将当前时间作为日期时间对象插入数据库?
【发布时间】:2018-12-17 17:37:23
【问题描述】:

我正在尝试通过当前时间。我对日期部分不感兴趣。

它必须作为 DateTime 对象传递才能成功存储在数据库中。

使用 Microsoft access 2003 作为数据库
编程语言是 C#
VS2017

【问题讨论】:

标签: c# datetime ms-access types datetime-format


【解决方案1】:

那么你应该将日期时间参数传递给它。

DateTime date_today = DateTime.Now;
SqlCommand sql_command = new SqlCommand("INSERT INTO table (date_time_table) VALUES (@value)", connection);
sql_command.Parameters.AddWithValue("@value", date_today);
sql_command.ExecuteNonQuery();

【讨论】:

    【解决方案2】:

    我找到了解决办法

    我已将时间列的默认值设置为名为 Time$() 的函数

    这将强制数据库自行将当前时间添加到我将每次自动添加的新行中

    如果您遇到同样的问题并找到我的答案并需要更多解释,请在您的问题中评论此答案。

    【讨论】:

      猜你喜欢
      • 2019-04-19
      • 1970-01-01
      • 2018-12-23
      • 2013-10-01
      • 2019-10-06
      • 2013-03-06
      • 2018-05-18
      相关资源
      最近更新 更多