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. GetFieldValue() throws an exception

GetFieldValue() throws an exception

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasehelp
2 Posts 2 Posters 9 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.
  • S Offline
    S Offline
    Stefan 0
    wrote on last edited by
    #1

    I have a code like this CString cSQL; CDatabase db; db.OpenEx( NULL, CDatabase::forceOdbcDialog ); CRecordset tbl( &db ); cSQL.Format( "SELECT * FROM tablename WHERE ID = %d", nID ); tbl.Open( CRecordset::forwardOnly, cSQL ); try { tbl.GetFieldValue( "ID", cSQL ); tbl.GetFieldValue( "ID", cSQL ); } catch( CException* e ) { char szCause[255]; e->GetErrorMessage( szCause, 255 ); e->Delete(); } The first GetFieldValue() call gets appropriate value into cSQL variable. But on the second GetFieldValue() call I get CDBException and the value of szCause is "" - empty string and m_nRetCode member of CException object is 100. What is wrong in this code? Any help would be very helpful. Thanks in advance. Stefan

    U 1 Reply Last reply
    0
    • S Stefan 0

      I have a code like this CString cSQL; CDatabase db; db.OpenEx( NULL, CDatabase::forceOdbcDialog ); CRecordset tbl( &db ); cSQL.Format( "SELECT * FROM tablename WHERE ID = %d", nID ); tbl.Open( CRecordset::forwardOnly, cSQL ); try { tbl.GetFieldValue( "ID", cSQL ); tbl.GetFieldValue( "ID", cSQL ); } catch( CException* e ) { char szCause[255]; e->GetErrorMessage( szCause, 255 ); e->Delete(); } The first GetFieldValue() call gets appropriate value into cSQL variable. But on the second GetFieldValue() call I get CDBException and the value of szCause is "" - empty string and m_nRetCode member of CException object is 100. What is wrong in this code? Any help would be very helpful. Thanks in advance. Stefan

      U Offline
      U Offline
      User 403
      wrote on last edited by
      #2

      The problem is most like caused because you're trying to access the same column's value twice. I haven't debugged into the GetFieldValue code but I do know from experience that you may only retrieve a column's value once and in the proper order. In other words, if you do SELECT *, you must access the columns in the same order as they appear on the table. If you do a SELECT COL1, COL2, ... you must call GetFieldValue for COL1 before calling it for COL2. I hope this helps, Alvaro

      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