ComplexDB: Demonstrates Complex Data Binding Using OLE DB Consumer Templates

Click to open or copy the ComplexDB project files.

This sample uses the OLE DB consumer template classes to create an ATL control that uses complex data binding to show data in a list box. A complex data-bound control uses the OLE DB data-binding interfaces (IDataSource and IRowPosition) to gain access to a rowset (see Creating a Complex Control).

To build the sample, make sure that the ActiveX Control Writer's SDK for OLE DB is installed and that you have added the relevant include and lib directories to your paths.

Once built, you can test the control by performing the following steps, or by building and running the MFCBind project that is part of this sample:

  1. Run the MFC AppWizard to create a dialog-based application (ensure you include the support for ActiveX controls).

  2. Once the project is generated by the wizard, right-click the dialog, select Insert ActiveX Control, and insert the control named "Microsoft ADO Data Control, version 6.0."

  3. Open the properties for that control and set the relevant properties to connect to a data source and run a command. For example:
    ConnectionString = DSN=OLE_DB_NWind_Jet
    RecordSource = select * from products
    
  4. Right-click the dialog and select Insert ActiveX Control, but this time insert the control named "ComplexCtl class" (this is the ComplexDB control you just built).

  5. Open the properties for that control and set the datasource property to the data source control you inserted in step 2. This is typically IDC_ADODC1.

  6. Set the FieldName to the field you want to display from the query.

  7. Build and run the application.

The value of the specified field for each record in the query should be displayed in the list box. You can also use the controls on the ADO data control to move forward and backward through the records.