CRecordset::DoFieldExchange
Called to exchange data (in both directions) between the field data members of the recordset and the corresponding record on the data source. Implements record field exchange (RFX).
virtual void DoFieldExchange(
CFieldExchange* pFX
);
Parameters
- pFX
A pointer to a CFieldExchange object. The framework will already have set up this object to specify a context for the field exchange operation.
Remarks
When bulk row fetching is not implemented, the framework calls this member function to automatically exchange data between the field data members of your recordset object and the corresponding columns of the current record on the data source. DoFieldExchange also binds your parameter data members, if any, to parameter placeholders in the SQL statement string for the recordset's selection.
If bulk row fetching is implemented, the framework calls DoBulkFieldExchange. To implement bulk row fetching, you must specify the CRecordset::useMultiRowFetch option of the dwOptions parameter in the Open member function.
Notes
DoFieldExchange is available only if you are using a class derived from CRecordset. If you have created a recordset object directly from CRecordset, you must call the GetFieldValue member function to retrieve data.
The exchange of field data, called record field exchange (RFX), works in both directions: from the recordset object's field data members to the fields of the record on the data source, and from the record on the data source to the recordset object.
The only action you must normally take to implement DoFieldExchange for your derived recordset class is to create the class with ClassWizard and specify the names and data types of the field data members. You might also add code to what ClassWizard writes to specify parameter data members or to deal with any columns you bind dynamically. For more information, see the article Recordset: Dynamically Binding Data Columns (ODBC).
When you declare your derived recordset class with ClassWizard, the wizard writes an override of DoFieldExchange for you, which resembles the following example:
void CCustomer::DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);
// Macros such as RFX_Text() and RFX_Int() are dependent on the
// type of the member variable, not the type of the field in the database.
// ODBC will try to automatically convert the column value to the requested type
RFX_Long(pFX, _T("[CustomerID]"), m_CustomerID);
RFX_Text(pFX, _T("[ContactFirstName]"), m_ContactFirstName);
RFX_Text(pFX, _T("[PostalCode]"), m_PostalCode);
RFX_Text(pFX, _T("[L_Name]"), m_L_Name);
RFX_Long(pFX, _T("[BillingID]"), m_BillingID);
pFX->SetFieldType(CFieldExchange::inputParam);
RFX_Text(pFX, _T("Param"), m_strParam);
}
For more information about the RFX functions, see the topic Record Field Exchange Functions.
For further examples and details about DoFieldExchange, see the article Record Field Exchange: How RFX Works. For general information about RFX, see the article Record Field Exchange.
Exceptions
This method can throw exceptions of type CDBException*.
Requirements
Header: afxdb.h