Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Parameters problem

Parameters problem

Scheduled Pinned Locked Moved Database
csharphelpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jonhbt
    wrote on last edited by
    #1

    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?

    A D B 3 Replies Last reply
    0
    • J jonhbt

      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?

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      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.

      J 1 Reply Last reply
      0
      • A Abhijit Jana

        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.

        J Offline
        J Offline
        jonhbt
        wrote on last edited by
        #3

        It didn't work either it is showwing me the following error.

        {System.Data.OleDb.OleDbException: Data type mismatch in criteria expression

        1 Reply Last reply
        0
        • J jonhbt

          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?

          D Offline
          D Offline
          DoctorMick
          wrote on last edited by
          #4

          If you step through the code and hover over todayDate and tomorrowDate what are there values?

          1 Reply Last reply
          0
          • J jonhbt

            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?

            B Offline
            B Offline
            Baran M
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups