Share via


Recordset: How Recordsets Update Records (ODBC)

OverviewHow Do IFAQSampleODBC Driver List

This article applies to the MFC ODBC classes. For DAO recordsets, see the article DAO Recordset.

Besides their ability to select records from a data source, recordsets can (optionally) update or delete the selected records or add new records. Three factors determine a recordset’s updatability: whether the connected data source is updatable, the options you specify when you create a recordset object, and the SQL that is created.

****Note   ****The SQL upon which your CRecordset object is based can affect your recordset’s updatability. For example, if your SQL contains a join or a GROUP BY clause, MFC sets the updatability to FALSE.

Note   This article applies to objects derived from CRecordset in which bulk row fetching has not been implemented. If you are using bulk row fetching, see the article Recordset: Fetching Records in Bulk (ODBC).

This article explains:

  • Your role in recordset updating and what the framework does for you.

  • The recordset as an edit buffer and the differences between dynasets and snapshots.

The article Recordset: How AddNew, Edit, and Delete Work (ODBC) describes the actions of these functions from the point of view of the recordset.

The article Recordset: More About Updates (ODBC) completes the recordset update story by explaining how transactions affect updates, how closing a recordset or scrolling affects updates in progress, and how your updates interact with the updates of other users.

Your Role in Recordset Updating

The following table shows your role in using recordsets to add, edit, or delete records, along with what the framework does for you.

Recordset Updating: You and the Framework

You... The framework...
Determine whether the data source is updatable (or appendable). Supplies member functions for testing the data source’s updatability or appendability.
Open an updatable recordset (of any type).
Determine whether the recordset is updatable by calling CRecordset update functions such as CanUpdate or CanAppend.
Call recordset member functions to add, edit, and delete records. Manages the mechanics of exchanging data between your recordset object and the data source.
Optionally, use transactions to control the update process. Supplies CDatabase member functions to support transactions.

For more information about transactions, see the article Transaction (ODBC).

The Edit Buffer

Taken collectively, the field data members of a recordset serve as an edit buffer that contains one record — the current record. Update operations use this buffer to operate on the current record.

  • When you add a record, the edit buffer is used to build a new record. When you finish adding the record, the record that was previously current becomes current again.

  • When you update (edit) a record, the edit buffer is used to set the field data members of the recordset to new values. When you finish updating, the updated record is still current.

When you call or , the current record is stored so it can be restored later as needed. When you call , the current record is not stored but is marked as deleted, and you must scroll to another record.

****Note   ****The edit buffer plays no role in record deletion. When you delete the current record, the record is marked as deleted, and the recordset is “not on a record” until you scroll to a different record.

Dynasets and Snapshots

Dynasets refresh a record’s contents as you scroll to the record. Snapshots are static representations of the records, so a record’s contents are not refreshed unless you call . To use all the functionality of dynasets, you must be working with an ODBC driver that conforms to the correct level of ODBC API support. For more information, see the articles ODBC and Dynaset.

See Also   Recordset: How AddNew, Edit, and Delete Work (ODBC)