Connect to the FoxPro database using ADO in Delphi

Source: Internet
Author: User
Tags dbase ole

Visualpro, that is, VFP, the little fox head, used it for database theoretical education at school, but it has never been in contact with it since 6.0. I have heard that there are 9.0, however, I think its era has passed. With the exception, I still find that some applications written using VFP are still called Erp. Is it incredible ?! In order to access the data in the VFP database (that is, the. DBF file), we had to re-pick up this "old antique ". Of course, I won't install another VFP6.0 for it. It should be connected through ADO. In addition, I can use Delphi to write a small program for a simple data query without complicated operations.

I started to use the adoconnection control to connect to the database, but I found that there is no driver suitable for VFP in the "provider" list! Create an ODBC
Link file can be referenced in ADO. Many VFP (or *) are listed in "ODBC data source Manager *. DBF). Unfortunately, it is a false driver. When you click it, a prompt is displayed asking you to download and install the driver (-_-!) :


Return to the adoconnection control and try to select "Microsoft
Ole db provider for ODBC drivers, and then, "1. Select use data source name", select "DBASE" in the list
Files "; 2. "Enter Login Server Information" can be ignored; "3. enter the initial directory to be used. copy the directory path of the DBF file to the directory. The complete connection string is "provider = msdasql.1; persist
Security info = false; Data Source = DBASE files; initial catalog = {data_path} "(where {data_path} is the. DBF storage path ). Click "test connection". Then, Try connecting the adotable and adoquery to a file. The data in the table is also displayed. However, this does not mean that it is completely successful. This is only because the DBASE driver is "partially compatible" with earlier VFP databases. When you try other. DBF Files, you will find an error:


When an "Unexpected error" occurs, you don't have to find the cause. It is estimated that the problem cannot be solved, because the driver is useless, so try another method. Haha ~


Starting with the driver of Google VFP, we found a tag entitled "not included in
Visual FoxPro ODBC of MDAC 2.6 or later
Driver "(this is machine translation) article, read the title will know that the VFP driver is really a year! Because at least mdac2.7 is used now. I found Microsoft
Ole db provider for Visual FoxPro 9.0, there seems to be no Chinese version, it will be used. Download and install sample data and program file, good! After the installation is complete (remember to restart Delphi), we found that the "provider" list of the adoconnection control contains an additional "Microsoft
Ole db provider for Visual FoxPro ", right, It is required!


Quickly use this number of driver connections and test the connection. We found that the file with the "DBASE files" Driver connection error can be connected normally. The complete connection string is: "provider = vfpoledb; Data
Source = {data_path}; Password = ""; collating sequence = machine"
({Data_path} is the. DBF storage path ).


Using the adotable control to retrieve data is simple. You can directly use the table name (that is, the file name of the. DBF file). When you use the adoquery control to query data, you can directly select
* From dbfilename ", where dbfilename is the. DBF file name, which can be an extension or extension.


As for more complex operations, you must try them slowly. It must be similar to operating the database. (^_^)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.