Using ADO Databinding in Visual C++

Using ADO databinding in Visual C++ requires the following steps.

To use ADO databinding in Visual C++

  1. Create an MFC Dialog application or MFC Formview application using the MFC AppWizard.

  2. Add the Microsoft ADO Data Control to the dialog box; see Inserting the Control into a Visual C++ Application.

  3. Point the ADO Data Control to your OLE DB data source.
    1. Right-click on the ADO Data Control and select Properties from the shortcut menu.

    2. On the Control tab, select the Use Connection String. You can use the supplied provider or you can delete it.

    3. Select Build. If you deleted the provider from Use Connection String, you will now be able to define one. After you define the provider, access the properties of the ADO Data Control again and select Build again to continue.

      If a provider is defined in Use Connection String before you select Build, you will now be able to define the data link properties. This displays the DataLink Wizard.

    4. Change the Provider if necessary, and define Location and Data Source values, as appropriate for your provider. For example, if you are using a SQL Server provider, Location specifies the database server and Data Source specifies the database. If you are using an ODBC provider, the Data Source corresponds to the ODBC DSN.

    5. Select the Authentication tab and set values for User Name and Password, if required by the data source.

    6. Return to the Connection tab and click Test Connection to test the data source. Scroll to the end of the Results window to see if the test passed. If it failed, check the configuration of your data source. Common errors include invalid passwords and incorrect values for the Location and Data Source fields.

    7. Exit the DataLink Wizard and return to the property sheet for the ADO Data Control.
  4. In the RecordSource tab, enter a query into the Command Text (SQL). The data-bound controls can bind to the results of this query. The query will usually be SQL. However, some OLE DB providers do not use SQL.

  5. Set any other ADO Data Control properties as needed and close the property sheet for the ADO Data Control.

  6. Add a data-bound control. For example, add the DataGrid control. (Do not confuse the DataGrid control with the RDO DBGrid control.)

  7. Set the DataGrid's properties.
    1. Right-click on the DataGrid and select Properties from the shortcut menu.

    2. Select the All tab and set the DataSource property to the ADO Data Control. Click on the DataSource drop-down list and find the ID of the ADO Data Control. The default ID name is IDC_ADODC1.
  8. To run in test mode, use CTRL+T. You will be able to scroll through the data. Use the Esc key or close the dialog box to end test mode.

If you compile and run the program, you will be able to scroll through the data as well.

Back to Databinding with ActiveX Controls in Visual C++.