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