在日期时间的C#格式字符串中的MYSQL日期时间列插入 [英] format string in datetime c# to insert in MYSQL datetime column
本文介绍了在日期时间的C#格式字符串中的MYSQL日期时间列插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有code是这样的:
I have code like this:
AutoParkDataDataContext Db = new AutoParkDataDataContext();
Dailyreport dailyRep = new Dailyreport();
string time = Convert.ToDateTime("10-10-2014 15:00:00");
dailyRep.order_time = time;
Db.Dailyreports.InsertOnSubmit(dailyRep);
Db.SubmitChanges();
当我看到它在 DailyReport
表它显示我只是日期(2014年10月10号00:00:00:00 )
,所以时间被忽略。我怎么能解决呢?
列类型为的DateTime
。
When I see it in the DailyReport
table it shows me only the date ("10-10-2014 00:00:00:00")
, so the time is ignored. How could i fix it?
The column type is DateTime
.
推荐答案
您行:
string time = Convert.ToDateTime("10-10-2014 15:00:00");
不应该编译。
Shouldn't compile.
我只能猜测,你没有的DateTime
在SQL Server的列的类型,你应该修改,以保持日期时间
,然后通过一个DateTime类型的对象,而不是字符串。
I can only guess that you don't have DateTime
as type of your column in SQL Server, you should modify it to keep DateTime
and then pass a DateTime type object, not a string.
这篇关于在日期时间的C#格式字符串中的MYSQL日期时间列插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文