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. CRecorset fails to retrive fields when there is only one record in recordset.

CRecorset fails to retrive fields when there is only one record in recordset.

Scheduled Pinned Locked Moved Database
helpdatabasec++
4 Posts 3 Posters 4 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
    Vaclav_
    wrote on last edited by
    #1

    I am having an issue with retrieving fields from MFC CRecordset. I am using GetFieldValue( index, strText ); Works fine until the opened recordset contains only one record. Than I get the first field OK, but then I get an error saying basically that the field has already been retrieved. Here it the error: Error: GetFieldValue operation failed on field %d. Data already fetched for this field. It seem that the field index is not being advanced.I stepped thru the GetFieldValue, but cannot find the actuall source for the error routine. If I do MoveFirst on this one record record set , I get an error that I am attempting to move past the beginning of the recordset.That would be expected. I am using VC 6.0 MFC with standard CRecordset and Access database with ODBC. So far Google is no help. Any pointers would be greatly appreciated. Thanks for your help. Vaclav

    S B 2 Replies Last reply
    0
    • V Vaclav_

      I am having an issue with retrieving fields from MFC CRecordset. I am using GetFieldValue( index, strText ); Works fine until the opened recordset contains only one record. Than I get the first field OK, but then I get an error saying basically that the field has already been retrieved. Here it the error: Error: GetFieldValue operation failed on field %d. Data already fetched for this field. It seem that the field index is not being advanced.I stepped thru the GetFieldValue, but cannot find the actuall source for the error routine. If I do MoveFirst on this one record record set , I get an error that I am attempting to move past the beginning of the recordset.That would be expected. I am using VC 6.0 MFC with standard CRecordset and Access database with ODBC. So far Google is no help. Any pointers would be greatly appreciated. Thanks for your help. Vaclav

      S Offline
      S Offline
      SilimSayo
      wrote on last edited by
      #2

      You should post this question under C/C++/MFC.

      1 Reply Last reply
      0
      • V Vaclav_

        I am having an issue with retrieving fields from MFC CRecordset. I am using GetFieldValue( index, strText ); Works fine until the opened recordset contains only one record. Than I get the first field OK, but then I get an error saying basically that the field has already been retrieved. Here it the error: Error: GetFieldValue operation failed on field %d. Data already fetched for this field. It seem that the field index is not being advanced.I stepped thru the GetFieldValue, but cannot find the actuall source for the error routine. If I do MoveFirst on this one record record set , I get an error that I am attempting to move past the beginning of the recordset.That would be expected. I am using VC 6.0 MFC with standard CRecordset and Access database with ODBC. So far Google is no help. Any pointers would be greatly appreciated. Thanks for your help. Vaclav

        B Offline
        B Offline
        bsdtux
        wrote on last edited by
        #3

        Are you advancing the index in the loop so that the loop will end if you have only on value? Also would it be possible to see the source for this.

        V 1 Reply Last reply
        0
        • B bsdtux

          Are you advancing the index in the loop so that the loop will end if you have only on value? Also would it be possible to see the source for this.

          V Offline
          V Offline
          Vaclav_
          wrote on last edited by
          #4

          I am sorry, I moved the question to MFC as suggested and did not even attempted to delete it here. I think it cannot be deleted once discussion starts. Yes, the field index is properly advanced and it works just fine with more than one record in the recordset - initially. The key is that I get the first field OK, than it fails on next one. I know the field is there because it retrives the record just fine when different SQL returns more records in recordset. Here is the code snippet, I have removed my // comments for clarity, but it is pretty normal text retrieval loop. pRecordset->AddNew(); fix , does not really adds anything pRecordset->MoveFirst(); should not need this on initial Open recordset short nFields = pRecordset->GetODBCFieldCount( ); while( !pRecordset->IsEOF( ) ) { buffer = strText.GetBuffer(256); // set item text for( short index = 0; index < nFields; index++ ) { pRecordset->GetFieldValue( index, strText ); buffer = strText.GetBuffer(256); pList->SetItemText(iItem,index,buffer); this is where it fails TRACE("\n item %i field %i buffer %s ",iItem , index , buffer ); } pRecordset->MoveNext( ); iItem++; } I would like to get you opinions on this if you have time to work on it. If so please switch to MFC forum. Thanks Vaclav

          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