Using OLE DB Record Views
The latest version of this topic can be found at Using OLE DB Record Views.
If you want to display OLE DB rowset data in an MFC application, you should use the MFC class COleDBRecordView. A record view object created from COleDBRecordView
allows you to display database records in MFC controls. The record view is a dialog form view directly connected to an OLE DB Rowset object created from the CRowset
template class. Obtaining a handle to the rowset object is simple:
COleDBRecordView myRecordView;
...
// CProductAccessor is a user record class
CRowset<CAccessor<CProductAccessor>> myRowSet = myRecordView.OnGetRowset();
The view displays the fields of the CRowset
object in the dialog's controls. The COleDBRecordView
object uses Dialog Data Exchange (DDX) and the navigational functionality built into CRowset
(MoveFirst, MoveNext
, MovePrev
, and MoveLast
) to automate the movement of data between the controls on the form and the fields of the rowset. COleDBRecordView
keeps track of the user's position in the rowset so that the record view can update the user interface and supplies an OnMove method for updating the current record before moving to another.
You can use DDX functions with COleDbRecordView to get data directly from the database recordset and display it in a dialog control. You should use the DDX_* methods (such as DDX_Text
), not the DDX_Field* functions (such as DDX_FieldText
) with COleDbRecordView.