如何将当前时间作为日期时间对象插入数据库?
How to insert current time to a database as a datetime object?
我正在尝试通过当前时间。我对日期部分不感兴趣。
它必须作为 DateTime 对象传递才能成功存储在数据库中。
使用 Microsoft access 2003 作为数据库
编程语言是C#
VS2017
那么你应该给它传递日期时间参数。
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();
我找到了解决方案
我已将我的时间列的默认值设置为名为 Time$()
的函数
这将强制数据库自行将当前时间添加到我每次都会自动添加的新行中
如果您遇到了同样的问题并找到了我的答案并且需要更多解释,请在您的问题中评论这个答案。
我正在尝试通过当前时间。我对日期部分不感兴趣。
它必须作为 DateTime 对象传递才能成功存储在数据库中。
使用 Microsoft access 2003 作为数据库
编程语言是C#
VS2017
那么你应该给它传递日期时间参数。
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();
我找到了解决方案
我已将我的时间列的默认值设置为名为 Time$()
的函数这将强制数据库自行将当前时间添加到我每次都会自动添加的新行中
如果您遇到了同样的问题并找到了我的答案并且需要更多解释,请在您的问题中评论这个答案。