Edit Method

See Also    Example    Applies To

Copies the current record from an updatable CdbRecordset object to the copy buffer for subsequent editing.

Syntax

VOIDEdit(VOID);

Remarks

Once you use the Edit method, changes made to the current record's fields are copied to the copy buffer. After you make the desired changes to the record, use the Update method to save your changes.

The current record remains current after you use Edit.

Caution If you edit a record and then perform any operation that moves to another record, without first using Update, your changes are lost without warning. In addition, if you close the CdbRecordset or end the procedure which declares the CdbRecordset or the parent CdbDatabase or CdbConnection object, your edited record is discarded without warning.

Using Edit produces an error if:

In a Microsoft Jet workspace, when the CdbRecordset object's LockEdits property setting is True (pessimistically locked) in a multiuser environment, the record remains locked from the time Edit is used until the update is complete. If the LockEdits property setting is False (optimistically locked), the record is locked and compared with the pre-edited record just before it's updated in the database. If the record has changed since you used the Edit method, the Update operation fails with a run-time error if you use OpenRecordset without specifying dbSeeChanges. By default, Microsoft Jet-connected ODBC and installable ISAM databases always use optimistic locking.

In an ODBCDirect workspace, once you edit and use Update to update a record’s primary key field, you can no longer edit fields in that record until you close the Recordset, and then retrieve the record again in a subsequent query.

Note To add, edit, or delete a record, there must be a unique index on the record in the underlying data source. If not, a "Permission denied" error will occur on the AddNew, Delete, or Edit method call in a Microsoft Jet workspace, or an "Invalid argument" error will occur on the Update call in an ODBCDirect workspace.

Usage

#include <afxole.h>
#include <dbdao.h>

CdbRecordset      rst;
...               // Open the recordset.
rst.Edit();         // Edit the current record.
...               // Make changes to the record.
rst.Update();      // Save the change.
...
rst.Close();         // Close the recordset.