0

"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.

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

2 Answers2

4

Try adding the parameter type:

OracleParameter p1 = new OracleParameter("AVAIL_DATE", OracleDbType.Date);
p1.Value = getDateToQuery();
ocmd.Parameters.Add(p1);

Also, make sure you provide the parameters in order, the last time I worked with Oracle I remember the names of the parameters were ignored.

Ulises
  • 13,229
  • 5
  • 34
  • 50
0

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));
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862