virtual void Delete( );
throw( CDBException );
Remarks
Call this member function to delete the current record. 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) in Visual C++ Programmer’s Guide.
Note 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 an example of how to do this, see the sample DBFETCH. For more information about bulk row fetching, see the article Recordset: Fetching Records in Bulk (ODBC) in Visual C++ Programmer’s Guide.
Caution 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.
Example
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( );
}
// ...
CRecordset Overview | Class Members | Hierarchy Chart
See Also Database::BeginTrans, CDatabase::CommitTrans, CDatabase::Rollback, CDBException