Error: OleDb Exception Was Unhandled Data type mismatch in criteria expression for Access Database in ASP.Net

Last Reply on May 03, 2017 03:13 AM By dharmendr

Posted on May 03, 2017 02:40 AM

hi Developers , when i retrive datas from database i got the following error. OleDb Exception Was Unhandled Data type mismatch in criteria expression. (Using Ms Access db) i don't know what is wrong with my code.below am adding my using code

string str = "select AttendanceLogs.*,Shifts.EndTime,Shifts.BeginTime,Shifts.Break1,Shifts.Break1BeginTime,Break1EndTime from AttendanceLogs inner join Shifts on Shifts.ShiftId = AttendanceLogs.ShiftId where AttendanceDate between '" + sDate + "' AND '" +tDate + "' and EmployeeId ='" + edr.GetValue(0) + "'";
OleDbCommand getLogs = new OleDbCommand(str, Conn);
OleDbDataReader dr = getLogs.ExecuteReader();

so please suggest me if i done any wron in my code.

thanks with Paul.S

You are viewing reply posted by: dharmendr on May 03, 2017 03:13 AM.
Posted on May 03, 2017 03:13 AM Modified on on May 03, 2017 03:14 AM
paulrajmca says:
string str = "select AttendanceLogs.*,Shifts.EndTime,Shifts.BeginTime,Shifts.Break1,Shifts.Break1BeginTime,Break1EndTime from AttendanceLogs inner join Shifts on Shifts.ShiftId = AttendanceLogs.ShiftId where AttendanceDate between '" + sDate + "' AND '" +tDate + "' and EmployeeId ='" + edr.GetValue(0) + "'";

 Change the above line with the below.

string str = "select AttendanceLogs.*,Shifts.EndTime,Shifts.BeginTime,Shifts.Break1,Shifts.Break1BeginTime,Break1EndTime from AttendanceLogs inner join Shifts on Shifts.ShiftId = AttendanceLogs.ShiftId where AttendanceDate between ('" + sDate + "' AND '" + tDate + "') and EmployeeId = " + edr.GetValue(0);

Guessing your employeeId is integer. That might be the cause.