2

This is the query I am having issues with:

cmd = new OleDbCommand(insert into tbl_Customer(cReportingTime) values (@ReportingTime)", con);
cmd.Parameters.Add("@ReportingTime", OleDbType.DBTime).Value = Time;
cmd.ExecuteNonQuery();

When I try to run it I am getting this error:

"Failed to convert parameter value from a DateTime to a TimeSpan"

I want to insert only time in MS Access database however I can't seem to get it to work.

Newd
  • 2,174
  • 2
  • 17
  • 31
Elixir
  • 287
  • 2
  • 3
  • 14
  • possible duplicate of [Convert DateTime to TimeSpan](http://stackoverflow.com/questions/17959440/convert-datetime-to-timespan) – fk2 Jun 18 '15 at 07:45
  • @fk2 It may be but I haven't found the answer from that question I had already seen and I got confused where to write Timeofday property. there was no Idea – Elixir Jun 18 '15 at 08:03

1 Answers1

3

I assume your Time is a DateTime, you can use it's TimeOfDay property like;

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

Since DBTYPE_DBTIME mapped with TimeSpan, this should work.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364