2015-06-18 17 views
2

這是我有問題的查詢:如何只在ms訪問中插入時間?

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數據庫I似乎無法得到它的工作。

+0

可能重複的[Convert DateTime to TimeSpan](http://stackoverflow.com/questions/17959440/convert-datetime-to-timespan) – fk2

+0

@ fk2它可能是但我還沒有找到該問題的答案我已經看到了,我很困惑在哪裏寫Timeofday屬性。沒有想法 – Elixir

回答

3

我假設你的TimeDateTime,你可以使用它的TimeOfDay property like;

cmd.Parameters.Add("@ReportingTime", OleDbType.DBTime).Value = Time.TimeOfDay; 

由於DBTYPE_DBTIMETimeSpan映射,這應該工作。

+0

是的這是工作謝謝 – Elixir