Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CRecordset::Delete

CRecordset::Delete 

Deletes the current record.


virtual void Delete( );

After a successful deletion, the recordset's field data members are set to a Null value, and you must explicitly call one of the Move functions in order to move off the deleted record. Once you move off the deleted record, it is not possible to return to it. If the data source supports transactions, you can make the Delete call part of a transaction. For more information, see the article Transaction (ODBC).

NoteNote

If you have implemented bulk row fetching, you cannot call Delete. This will result in a failed assertion. Although class CRecordset does not provide a mechanism for updating bulk rows of data, you can write your own functions by using the ODBC API function SQLSetPos. For more information about bulk row fetching, see the article Recordset: Fetching Records in Bulk (ODBC).

Caution noteCaution

The recordset must be updatable and there must be a valid record current in the recordset when you call Delete; otherwise, an error occurs. For example, if you delete a record but do not scroll to a new record before you call Delete again, Delete throws a CDBException.

Unlike AddNew and Edit, a call to Delete is not followed by a call to Update. If a Delete call fails, the field data members are left unchanged.

This method can throw exceptions of type CDBException*.

This example shows a recordset created on the frame of a function. The example assumes the existence of m_dbCust, a member variable of type CDatabase already connected to the data source.

// Create a derived CRecordset object
CCustSet rsCustSet( &m_dbCust );
rsCustSet.Open( );

if( rsCustSet.IsEOF( ) || !rsCustSet.CanUpdate( ) ||
    !rsCustSet.CanTransact( ) )
   return;

if( !m_dbCust.BeginTrans( ) )
{
   // Do something to handle a failure
}
else
{
   // Perhaps scroll to a new record...
   // Delete the current record
   rsCustSet.Delete( );
   // ...

   // Finished commands for this transaction
   if( <the user confirms the transaction> )
      m_dbCust.CommitTrans( );
   else // User changed mind
      m_dbCust.Rollback( );
}
// ...

Community Additions

ADD
Show:
© 2015 Microsoft