这是我遇到问题的查询:
cmd = new OleDbCommand(insert into tbl_Customer(cReportingTime) values (@ReportingTime)", con);
cmd.Parameters.Add("@ReportingTime", OleDbType.DBTime).Value = Time;
cmd.ExecuteNonQuery();
当我尝试运行它时,我收到此错误:
"Failed to convert parameter value from a DateTime to a TimeSpan"
我想只在MS Access数据库中插入时间,但我似乎无法让它工作。
答案 0 :(得分:3)
我认为您的Time
是DateTime
,您可以像TimeOfDay
property一样使用它;
cmd.Parameters.Add("@ReportingTime", OleDbType.DBTime).Value = Time.TimeOfDay;
由于DBTYPE_DBTIME
映射到TimeSpan
,这应该有用。