c# - Oracle DataReader Erroring on GetDateTime -
i have particular data row throwing error when try read in particular date column - "year, month, , day parameters describe un-representable datetime".
i'm pulling in several hundred rows of data , work except 1 row. can pull in other columns problematic row except 1 datetime column. i'm using oracle data reader fetch datetime database, can use watch tool in visual studio examine row i'm read in. looks in watch tool - sees column i'm trying read in datetime , has of it's properties.
while (reader.read()) { var temp = new fccondition(); temp.caseid = reader.getstring(0); temp.statute = reader.getstring(1); if (!reader.isdbnull(2)) temp.duedate = reader.getdatetime(2); if (!reader.isdbnull(3)) temp.hoursassigned = reader.getint32(3); if (!reader.isdbnull(4)) temp.hourscompleted = reader.getint32(4); temp.jwconditionid = reader.getstring(5); if (!reader.isdbnull(6)) temp.startdate = reader.getdatetime(6); if (!reader.isdbnull(7)) temp.statusdate = reader.getdatetime(7); if (temp.duedate <= temp.startdate) temp.duedate = temp.startdate.addmonths(18); fcconditionslist.add(temp); } }
the 1 throwing error while reading in startdate (reader.getdatetime(6)). have tried storing in var , bringing w/ reader.getoracledate , reader.getvalue , still throw same error.
the datetime i'm trying read in has value of: 6/7/2017 5:16:41 pm i've included screen shot of watch tool in state right before tries read in column
i suspect getdatetime
call not expecting am/pm symbol? such can't identify valid date/time. try this:
if (!reader.isdbnull(6)) { var temporarydate = reader.getvalue(6).tostring(); datetime outdate; if (datetime.tryparseexact(temporarydate, "m/dd/yyyy h:mm:ss tt", null, datetimestyles.none, out outdate)) { temp.startdate = outdate; } }
edit: faced same issue myself today , solved differently... using oracle data access managed client
if (!reader.isdbnull(6)) { var tempdate = reader.getoracledate(6); temp.startdate = new datetime(tempdate.year, tempdate.month, tempdate.day, tempdate.hour, tempdate.minute, tempdate.second); }
Comments
Post a Comment