Condividi tramite


CRecordset::Delete

Deletes the current record.

virtual void Delete( );

Remarks

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).

Nota

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).

Avviso

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.

Exceptions

This method can throw exceptions of type CDBException*.

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
CCustomer rsCustSet(&m_dbCust);
rsCustSet.Open();

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

m_dbCust.BeginTrans();

// Perhaps scroll to a new record...
// Delete the current record
rsCustSet.Delete();

// Finished commands for this transaction
if(IDYES == AfxMessageBox(_T("Commit transaction?"), MB_YESNO))
   m_dbCust.CommitTrans();
else // User changed mind
   m_dbCust.Rollback();

Requirements

Header: afxdb.h

See Also

Reference

CRecordset Class

Hierarchy Chart

CDatabase::BeginTrans

CDatabase::CommitTrans

CDatabase::Rollback

CDBException Class

Other Resources

CRecordset Members