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 / C++ / MFC
  4. still can't use SQL database

still can't use SQL database

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestion
5 Posts 3 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.
  • H Offline
    H Offline
    halblonious
    wrote on last edited by
    #1

    Here's what I've got: CDatabase DataBase; TRY { DataBase.OpenEx(_T("DSN=test;UID=;PWD="),CDatabase::noOdbcDialog); } CATCH(CDBException,e) { #ifdef _DEBUG MessageBox("ERROR Connecting"); #endif } END_CATCH TRY { DataBase.ExecuteSQL("INSERT INTO Annotation (AnnotationID,ImageID,Text) VALUES ('1','2','Capsule')"); } CATCH(CDBException,e) { #ifdef _DEBUG MessageBox("ERROR Inserting"); #endif } END_CATCH It appears to be connecting fine, but I always get "ERROR Inserting". 'Annotation' is the table I'm trying modify fields in. When I set up my DSN, I put the default database to the one that the table 'Annotation' is in (instead of master or model, etc). What am I doing wrong or failing to do? halblonious

    V S 2 Replies Last reply
    0
    • H halblonious

      Here's what I've got: CDatabase DataBase; TRY { DataBase.OpenEx(_T("DSN=test;UID=;PWD="),CDatabase::noOdbcDialog); } CATCH(CDBException,e) { #ifdef _DEBUG MessageBox("ERROR Connecting"); #endif } END_CATCH TRY { DataBase.ExecuteSQL("INSERT INTO Annotation (AnnotationID,ImageID,Text) VALUES ('1','2','Capsule')"); } CATCH(CDBException,e) { #ifdef _DEBUG MessageBox("ERROR Inserting"); #endif } END_CATCH It appears to be connecting fine, but I always get "ERROR Inserting". 'Annotation' is the table I'm trying modify fields in. When I set up my DSN, I put the default database to the one that the table 'Annotation' is in (instead of master or model, etc). What am I doing wrong or failing to do? halblonious

      V Offline
      V Offline
      Vic Mackey
      wrote on last edited by
      #2

      Taking a look at e->m_strError to see what the error is seems like a logical first step ;)

      H 1 Reply Last reply
      0
      • V Vic Mackey

        Taking a look at e->m_strError to see what the error is seems like a logical first step ;)

        H Offline
        H Offline
        halblonious
        wrote on last edited by
        #3

        I never even knew to check that. Sadly, though, it doesn't really tell me much. Do you know of a good place to find prototype syntax for this stuff? What I had works for modifying an Access database, but doesn't seem to work on SQL. halblonious

        V 1 Reply Last reply
        0
        • H halblonious

          I never even knew to check that. Sadly, though, it doesn't really tell me much. Do you know of a good place to find prototype syntax for this stuff? What I had works for modifying an Access database, but doesn't seem to work on SQL. halblonious

          V Offline
          V Offline
          Vic Mackey
          wrote on last edited by
          #4

          could you post the error message?

          1 Reply Last reply
          0
          • H halblonious

            Here's what I've got: CDatabase DataBase; TRY { DataBase.OpenEx(_T("DSN=test;UID=;PWD="),CDatabase::noOdbcDialog); } CATCH(CDBException,e) { #ifdef _DEBUG MessageBox("ERROR Connecting"); #endif } END_CATCH TRY { DataBase.ExecuteSQL("INSERT INTO Annotation (AnnotationID,ImageID,Text) VALUES ('1','2','Capsule')"); } CATCH(CDBException,e) { #ifdef _DEBUG MessageBox("ERROR Inserting"); #endif } END_CATCH It appears to be connecting fine, but I always get "ERROR Inserting". 'Annotation' is the table I'm trying modify fields in. When I set up my DSN, I put the default database to the one that the table 'Annotation' is in (instead of master or model, etc). What am I doing wrong or failing to do? halblonious

            S Offline
            S Offline
            Steve S
            wrote on last edited by
            #5

            At a guess, AnnotationID and ImageID are numeric (integer?) types. Try removing the quoting around them so it's just VALUES(1,2,'Capsule') Of course, there may also be uniqueness constraints which stop you inserting the same values more than once... Steve S

            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