Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss. print.
VFP AND ADO (PART 1 OF 2)

Microsoft Knowledge Base article Q168335 (http://support.microsoft.com/support/kb/articles/Q168/3/35.asp) provides us with a brief description of what ADO means:

"ActiveX Data Objects is a programming model, which means that it is not dependent upon any given back-end engine. Currently, however, the only engine supporting the ADO model is OLE-DB. There are many native OLE-DB Providers as well as an OLE-DB Provider for ODBC."

The ADO object model consists of six objects:

- Connection: Represents an open connection, in this case to an OLE-DB datasource that can be an ODBC data source, using MSDASQL (the Microsoft OLE-DB provider for ODBC).
- Error: Contains details about data access errors, refreshed for each time an error occurs in a single operation involving ADO.
- Command: Defines a specific command you wish to execute against data.
- Parameters: Optional collection off the command object for any parameters you wish to provide to the command.
- Recordset: Represents a set of records from a table, command object, or SQL Syntax. Can be created without any underlying Connection object.
- Field: Represents a single column of data in a recordset.
- Property: A collection of values raised by the provider for ADO.

The next two items were new in 2.5:

- Stream: Provides the means to read or write binary information or text.
- Record: Can represent a row in a recordset or a directory or a file.
- ADO/R is a subset of this ADO object model used with the Advanced Data Connector that provides only the Recordset and Field objects."

You may also like to check out http://msdn.microsoft.com/library/techart/adojump.htm

VFPADO Example
This form shows how to use the ADO Connection and Record Set to talk to a Microsoft Access Database. It will display the contents of one of the tables in the Microsoft ListView control. I now use this control instead of the VFP Grid control, I am working on a full document for this control and how to use in VFP (this will be available shortly). The init method of the form, creates two new properties and creates the ADO Connection and RecordSet Objects. The Code is full commented and should be easy to follow.

The connection string, is a DSN-Less connection so an ODBC connection string is not required, this can be changed to talk to any data source:- Oracle, SQL Server and others. If you want to use ADO with VFP and FoxPro Tables, you will need to use the VFPCOM dll, that will allow you to convert a cursor to an ADO Recordset and vice-versa. I will create an example of this with full comments on how this can be achieved. This was created as an example to show how easy it is to get VFP to use the ADO features. This example requires the following controls:

MSCOMCTL.OCX
Microsoft Jet 4.0 Driver (ODBCJT32.DLL)

Download code
You can download Simons sample here: http://www.xs4all.nl/~foxite/downloads/vfpado.zip. The download is a zipfile. Its size is 38.912 bytes.

ABOUT THE AUTHOR: SIMON ARNOLD

Simon Arnold Simon has worked with FoxPro for over 16 years. He currently works for a company based in Harrogate, North Yorkshire (UK), which specialises in FoxPro, Web and Unix development.
He has a weblog at http://weblogs.foxite.com/simonarnold.

FEEDBACK


Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: