2/1/2009 5:04:15 AM
我从 MySQL 数据库获取它,并想将它从我获取它的其他地方提供到表中。
但它在 C# 中不起作用,但使用 gui 它可以。
我如何使用 C# 代码将此日期提供给 MySQL 数据库。
最佳答案
如果您使用 MySqlCommand
类,您应该能够使用具有以下结构的 DateTime
:
using (var command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO table (dateTimeColumn) VALUES (@1)";
command.Parameters.AddWithValue("@1", DateTime.Now);
command.ExecuteNonQuery();
}
这应确保正确存储日期/时间。
关于c# - 如何使用 C# 代码在 MySql 数据库中插入 DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4153799/