I am trying to retrieve data from oracle database between 2 dates. I keep getting the following error:
An exception of type 'Oracle.ManagedDataAccess.Client.OracleException' occurred in Oracle.ManagedDataAccess.dll but was not handled in user code
I'm not sure if the problem from the query I wrote:
public List<GetterAndSetterObj> GetDataBasedOnSelectedPeriod(DateTime fromDate, DateTime toDate)
{
using (ProdOracleContext oracleContext = new ProdOracleContext())
{
using (OracleCommand command = oracleContext.CreateCommand)
{
command.CommandText = string.Format("select * from datesTable where TRUNC(dates) BETWEEN TO_DATE('{0}','DD-MON-RRRR') AND TO_DATE('{1}','DD-MON-RRRR')", fromDate, toDate);
var queryResult = oracleContext.Get(command);
var list_v_sum_slaies_by_lice_no = new List<getterAndSetterObj>();
foreach (DataRow row in queryResult.Rows)
{
finalList.Add(new getterAndSetterObj
{
LICENCE_NUMBER = row["LICENCE_NUMBER"].ToString(),
SHOP_NAME = row["SHOP_NAME"].ToString(),
dates= row.Field<DateTime>("dates"),
SUM_ALL = int.Parse(row["SUM_ALL"].ToString())
});
} return finalList;
}
}
}
Then I call the function using these method:
public List<v_sum_slaies_by_lice_no> GetDataBasedOnSelectedPeriod(string fromDate, string toDate)
{
DateTime OfromDate = DateTime.ParseExact(fromDate, "dd/MM/yyyy", null);
DateTime OtoDate = DateTime.ParseExact(toDate, "dd/MM/yyyy", null);
return dataBase.GetDataBasedOnSelectedPeriod(OfromDate, OtoDate);
}
note, the input would be something like this: 20/06/2019 22/06/2019
Note, the date stored on the database as a datetime which include the time and I want to get the data based on the date only