Microsoft KB Archive/261108

= How To Use ADO in VFP Interactively with the ADO Control =

Article ID: 261108

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Data Access Components 2.6

-



This article was previously published under Q261108



SUMMARY
Normally, when using ActiveX Data Objects (ADO) in Visual FoxPro, code is written to make a call to an ODBC driver, which then retrieves the data. The same result can be accomplished interactively in a Visual FoxPro form by using the ADO Data control to access a table using an ODBC driver. You may display the results by using the DataGrid control.

NOTE: The DataGrid control has not been tested with and is not supported by Microsoft Visual FoxPro.



MORE INFORMATION
Even though the ADO control is not visible when the form runs, it has properties that allow the user to change the table and/or datasource interactively. These controls are shipped with Visual FoxPro 6.0.  Create a form, select the OLE ActiveX (Olecontrol) button from the Form Controls toolbar, and then click on the form. Select the Insert Control button, and then scroll down and select Microsoft ADO Data, version 6.0.  After deciding which ODBC datasource and table that you want to access, go to the properties sheet of the form and change the following properties on Olecontrol1: CommandType - &quot;2 - Table Command&quot; ConnectionString - DSN= RecordSource - Make sure that DSN= is in front of your datasource name.

 From the Form Controls toolbar, select the OLE ActiveX (Olecontrol) button to create a second olecontrol. After clicking on your form, select the Insert Control button and choose Microsoft DataGrid Control, version 6.0.  Add the following code to the Init event of the form and run the form: Thisform.Olecontrol2.DataSource = Thisform.Olecontrol1.Object After the form runs, the grid is populated with data from the table.

  If the user wants to change the data in the DataGrid control interactively, then change the table name and/or datasource of the ADO Data control. For example, drop a Command button on the form and add the following code to the click event: Thisform.Olecontrol1.ConnectionString='DSN=<your datasource' Thisform.Olecontrol1.RecordSource=' ' Thisform.Olecontrol2.DataSource=Thisform.Olecontrol1.Object Thisform.Refresh </li> Click the Command button, and note that the grid is populated with data from the other table.</li></ol>

<div class="references_section">