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. General Programming
  3. C#
  4. OdbcDataReader

OdbcDataReader

Scheduled Pinned Locked Moved C#
databasehelp
3 Posts 2 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.
  • V Offline
    V Offline
    viliam
    wrote on last edited by
    #1

    Hi, I am fighting with SQL syntax. My database is MDB file, all reading work fine except DateTime columns. this code: string cmdR = "select M_TEMP from MEASUREMENT where M_TIME = '2007-11-16 13:10:00'"; using (OdbcCommand catCMD = new OdbcCommand(cmdR, mConn))¨ OdbcDataReader myReader = catCMD.ExecuteReader(); ... give me exception (ExecuteReader()): System.Data.Odbc.OdbcException with error: Data type mismatch in criteria expression. I tried various combination, for 'M_TIME = #'2007-11-16 13:10:00'# then error was: Syntax error in date in query expression 'M_TIME = #'2007-11-16 13:10:00'#' The closest probably was 'M_TIME = #2007-11-16 13:10:00# there were no exception but it select the first item except the one from the requsted time and i am still not able to find the way to insert time in correct way. Thank you for help to undertand this Viliam

    viliam

    OriginalGriffO 1 Reply Last reply
    0
    • V viliam

      Hi, I am fighting with SQL syntax. My database is MDB file, all reading work fine except DateTime columns. this code: string cmdR = "select M_TEMP from MEASUREMENT where M_TIME = '2007-11-16 13:10:00'"; using (OdbcCommand catCMD = new OdbcCommand(cmdR, mConn))¨ OdbcDataReader myReader = catCMD.ExecuteReader(); ... give me exception (ExecuteReader()): System.Data.Odbc.OdbcException with error: Data type mismatch in criteria expression. I tried various combination, for 'M_TIME = #'2007-11-16 13:10:00'# then error was: Syntax error in date in query expression 'M_TIME = #'2007-11-16 13:10:00'#' The closest probably was 'M_TIME = #2007-11-16 13:10:00# there were no exception but it select the first item except the one from the requsted time and i am still not able to find the way to insert time in correct way. Thank you for help to undertand this Viliam

      viliam

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Looking at this[^] you may find that

      string cmdR = "select M_TEMP from MEASUREMENT where M_TIME = ts'2007-11-16 13:10:00'";
      using (OdbcCommand catCMD = new OdbcCommand(cmdR, mConn))
      {
      OdbcDataReader myReader = catCMD.ExecuteReader();
      ...
      }

      may work - I don't know for sure, (I don't use ODBCas my DBs are mySQL) Oh, and the convention for database access seems to be:

      string cmdR = "SELECT field FROM table WHERE field = value";

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      V 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Looking at this[^] you may find that

        string cmdR = "select M_TEMP from MEASUREMENT where M_TIME = ts'2007-11-16 13:10:00'";
        using (OdbcCommand catCMD = new OdbcCommand(cmdR, mConn))
        {
        OdbcDataReader myReader = catCMD.ExecuteReader();
        ...
        }

        may work - I don't know for sure, (I don't use ODBCas my DBs are mySQL) Oh, and the convention for database access seems to be:

        string cmdR = "SELECT field FROM table WHERE field = value";

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        V Offline
        V Offline
        viliam
        wrote on last edited by
        #3

        Thank you but there is still the exception Syntax error (missing operator) in query expression 'M_TIME = ts'2007-01-12 13:10:00''.

        viliam

        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