Parameters problem
-
I am running the following MS ACCESS select command from a c# method.
SELECT USERINFO.USERID, CHECKINOUT.CHECKTIME, CHECKINOUT.CHECKTYPE, DEPARTMENTS.DEPTNAME, USERINFO.NAME FROM (CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID) INNER JOIN DEPARTMENTS ON USERINFO.DEFAULTDEPTID = DEPARTMENTS.DEPTID WHERE CHECkINOUT.CHECKTIME BETWEEN @fromDate and @toDate " + sensors + "ORDER BY DEPARTMENTS.DEPTNAME;"
The problem is that the parameters that I am passing, which are in date format are throwing an ivalid criteria exception. This is how I am passing the parameters
cmd.Parameters.AddWithValue("fromDate", todayDate);
cmd.Parameters.AddWithValue("toDate", tomorrowDate);Can one identify why it is telling me ivalid criteria when the values should be dates?
-
I am running the following MS ACCESS select command from a c# method.
SELECT USERINFO.USERID, CHECKINOUT.CHECKTIME, CHECKINOUT.CHECKTYPE, DEPARTMENTS.DEPTNAME, USERINFO.NAME FROM (CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID) INNER JOIN DEPARTMENTS ON USERINFO.DEFAULTDEPTID = DEPARTMENTS.DEPTID WHERE CHECkINOUT.CHECKTIME BETWEEN @fromDate and @toDate " + sensors + "ORDER BY DEPARTMENTS.DEPTNAME;"
The problem is that the parameters that I am passing, which are in date format are throwing an ivalid criteria exception. This is how I am passing the parameters
cmd.Parameters.AddWithValue("fromDate", todayDate);
cmd.Parameters.AddWithValue("toDate", tomorrowDate);Can one identify why it is telling me ivalid criteria when the values should be dates?
jonhbt wrote:
The problem is that the parameters that I am passing, which are in date format are throwing an ivalid criteria exception. This is how I am passing the parameters cmd.Parameters.AddWithValue("fromDate", todayDate); cmd.Parameters.AddWithValue("toDate", tomorrowDate);
You didn't use
**@**
with the parameter. Here is you modified code,cmd.Parameters.AddWithValue("@fromDate", todayDate);
cmd.Parameters.AddWithValue("@toDate", tomorrowDate);This will help you :)
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
jonhbt wrote:
The problem is that the parameters that I am passing, which are in date format are throwing an ivalid criteria exception. This is how I am passing the parameters cmd.Parameters.AddWithValue("fromDate", todayDate); cmd.Parameters.AddWithValue("toDate", tomorrowDate);
You didn't use
**@**
with the parameter. Here is you modified code,cmd.Parameters.AddWithValue("@fromDate", todayDate);
cmd.Parameters.AddWithValue("@toDate", tomorrowDate);This will help you :)
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
I am running the following MS ACCESS select command from a c# method.
SELECT USERINFO.USERID, CHECKINOUT.CHECKTIME, CHECKINOUT.CHECKTYPE, DEPARTMENTS.DEPTNAME, USERINFO.NAME FROM (CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID) INNER JOIN DEPARTMENTS ON USERINFO.DEFAULTDEPTID = DEPARTMENTS.DEPTID WHERE CHECkINOUT.CHECKTIME BETWEEN @fromDate and @toDate " + sensors + "ORDER BY DEPARTMENTS.DEPTNAME;"
The problem is that the parameters that I am passing, which are in date format are throwing an ivalid criteria exception. This is how I am passing the parameters
cmd.Parameters.AddWithValue("fromDate", todayDate);
cmd.Parameters.AddWithValue("toDate", tomorrowDate);Can one identify why it is telling me ivalid criteria when the values should be dates?
If you step through the code and hover over todayDate and tomorrowDate what are there values?
-
I am running the following MS ACCESS select command from a c# method.
SELECT USERINFO.USERID, CHECKINOUT.CHECKTIME, CHECKINOUT.CHECKTYPE, DEPARTMENTS.DEPTNAME, USERINFO.NAME FROM (CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID) INNER JOIN DEPARTMENTS ON USERINFO.DEFAULTDEPTID = DEPARTMENTS.DEPTID WHERE CHECkINOUT.CHECKTIME BETWEEN @fromDate and @toDate " + sensors + "ORDER BY DEPARTMENTS.DEPTNAME;"
The problem is that the parameters that I am passing, which are in date format are throwing an ivalid criteria exception. This is how I am passing the parameters
cmd.Parameters.AddWithValue("fromDate", todayDate);
cmd.Parameters.AddWithValue("toDate", tomorrowDate);Can one identify why it is telling me ivalid criteria when the values should be dates?
Do you find any difficulties to use Add() Function, cmd.Parameters.Add("@fromDate", SqlDbType.System.Data.SqlDbType.Date) cmd.Parameters.Item(0).Value = todayDate; Using Add() function you can avoid datatype conflicts here.
Education is not a way to escape poverty — it is a way of fighting it.