Search code examples
c#winformsoracle-databasedatetimedotconnect

In what format does Oracle expect a date value, and how can I give Oracle what it wants?


"AVAILABLEDATE" is a column of type DATE.

I can query the table via Toad and get results. However, in (Winforms/C#/dotConnect) code, it's not working.

ocmd.Parameters.Add("AVAIL_DATE", getDateToQuery());

I'm pretty sure the problem is the way I'm passing the date:

private DateTime getDateToQuery() {
  DateTime candidateVal = dateTimePickerScheduleDate.Value;
  if (candidateVal.Equals(null)) {
    candidateVal = DateTime.Now;
  }
  return candidateVal;
}

...but I don't know how to force the date value to be in the format Oracle will recognize.


Solution

  • This works, but I'm not sure it's the best way:

    int iFromYear = dateTimePickerScheduleDate.Value.Year;
    int iFromMonth = dateTimePickerScheduleDate.Value.Month;
    int iFromDay = dateTimePickerScheduleDate.Value.Day;
    . . .
    ocmd.Parameters.Add("AVAIL_DATE", new DateTime(iFromYear, iFromMonth, iFromDay));