Update() on valid recordset returns error "The row to update could not be found." 
Author Message
 Update() on valid recordset returns error "The row to update could not be found."

I have two functions ("Activate", and "Retire") in a C++ COM server app
which change the setting of a single field in a single record in one of my
tables.  The field is a Yes/No field in an Access database.  I am seeing a
strange problem when a client attempts to call these 2 functions right after
one another.  My server queries the database for the record, finds it, sets
the value of the field, and then tries to call Recordset::Update()

The thing is, the first time a client calls one of these functions,
everything goes through fine, but the second time, I get an error from ADO
which evaluates to the following

   "Query based update failed. The row to update could not be found."

This makes no sense to me since I have just queried the database and gotten
a valid recordset with the row I requested before attempting to update it.

Can anyone tell me what's going on here?  Is this just a limitation of MS
Access?  It seems if I step through it slowly in the de{*filter*} it doesn't

Here's my code.  This is just the Activate function, which sets the field
("Retired") to VARIANT_FALSE.  The Retire function is almost identical but
it sets the database field to VARIANT_TRUE

HRESULT CAlleleManager::ActivateAllele(BSTR bstrName)
      CStdString strAlleleName(bstrName);

      // Get an ADO Connection object for this thread and build an ADO
recordset on it

      _ConnectionPtr pConn = _Module.GetAdoConnection();
      _RecordsetPtr pSet(__uuidof(Recordset));
      ASSERT(pSet != NULL);

      // Now query the Allele database for this allele.

      _bstr_t bstrEmpty = L"";
      CStdString strSql;
      strSql.Format(_T("SELECT * FROM DNAAllele WHERE Name = \'%s\'"),
      pSet->Open(T2COLE(strSql), vtMissing, adOpenForwardOnly,
adLockOptimistic, adCmdUnspecified);

     // If we did not find the matching record, throw an exception (NEVER

     if ( pSet->ADOEOF == VARIANT_TRUE )
         throw std::exception(T2CA((_T("Unable to find allele ") +
                                                 strAlleleName +
                                                 _T(" in database -- cannot

      // Now set the allele's boolean retired member the database

     pSet->Fields->Item[_variant_t((L"Retired"))]->Value =

     // Try to update the database.  Here is where the code fails.

     pSet->Update();   // ******** THIS FAILS AND THROWS EXCEPTION;

      hr = S_OK;
   catch(_com_error& err)
        // Here, if I query the ADO _Connection object for its Errors
collection, I get back
        // the following string
        //  "Query based update failed. The row to update could not be
        // However I KNOW that pSet was valid and that it had records in it.

   return hr;


Fri, 12 Jan 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Q: Error message "Multiple rows updated"???

2. ODBC: "Multiple rows were updated" ERROR

3. ADO storedproc error: Updating not allowed on recordset

4. SQL/VC++ Updates: Can't update recordset

5. Not able to update large table using dynaset recordset

6. OLE DB: Error update row

7. single row updates effect multiple rows....

8. Row update SQL error

9. Help: "Multiple rows were updated error' or is problem MFC's Update()

10. Not All Control Paths Return A Value/ Everything Is Not Valid

11. Update error - Input string was not in a correct format

12. Could not update, currently locked, error using VC++ 6.0


Powered by phpBB® Forum Software