I am trying to select data from my Oracle database BY DATE using C#. However I am always getting an empty data set although the same query string works just fine in Oracle SQL Developer
String Query = "Select position_date from position";
OracleDataAdapter adapter = new OracleDataAdapter(Query, ocon);
adapter.Fill(ds, "table"); //where ds is a dataset
PrintDataSet(ds);
returns
3/8/2011 12:00:00 AM.... and more
However, when I change my query to below, then there is no output!
String Query = "Select position_date from position
where to_char(position_date, 'mm-dd-yyyy') = '05-17-2012'"
This query works fine in oracle sql developer. I've also tried trunc(sysdate) but nothing seems to work! :(
3/8/2011is a completely different day than05-17-2012. It does make sense to me that you are not getting anything back. And you should not convert the date to a string but the string to a date. Usingposition_date = to_date('05-17-2012', 'mm-dd-yyyy')will enable Oracle to use an index on position_date.