ASP's operation on FoxPro free-form (DBF file)

Source: Internet
Author: User
Tags date insert sql pack relative table name access

First, the question of the proposed
The most recent project encountered ASP pairs of FoxPro library tables (*. DBF) operation problem. In reality, many applications use DBF tables, how to use these data in the network environment, so many friends are helpless.
I also checked a lot of information, did not find a detailed explanation for the solution. After the test, the preliminary solution to this problem, take out and share with you.
This article attempts to address the following issues:
1. asp joins the free table generated by FoxPro (*.dbf file)
2. Multiple types of data and graphics files stored in the DBF table
(sample programs are available from Http://www.netop.cc/downloads/dbf.rar)

Second, the environment
Windows2000 + IIS5.0 + IE6.0 (SP1)
DBF file is a free table generated by Microsoft Visual FoxPro 6.0 (non-DBC library)

Iii. ways of solving the problem
1. Connection
The ODBC driver name for the DBF file is Microsoft Visual FoxPro Driver, which, in ASP, is joined by Connection objects, and it is necessary to note that the directory in which DBF is located is considered the library name when joining. The following are the specific join codes:

DIM conn,connstr,db
db= "Data"
Set conn = Server.CreateObject ("ADODB. Connection ")
ConnStr = "Driver={microsoft Visual FoxPro Driver}; sourcetype=dbf; " &_
"Sourcedb=" & Server.MapPath (db) &; Exclusive=no "
Conn. Open ConnStr

In the above code, data is the relative path of my dbf file (relative to the file in which this code is located), and it is converted to an absolute path through Server.MapPath (db).
Http://www.connectionstrings.com gives a number of types of library table file connection strings, of which the DBF file, given the connection string is:
"Driver={microsoft DBASE Driver (*.dbf)};D Riverid=277;dbq=c:\mydbpath;"
I use this connection string is not connected successfully, no further testing, interested friends can try the above string.

2. Declare the table name in the SQL statement
You can declare the table name you want to manipulate in the SQL statement in the form of table name or table name. Extension, such as a table file named T1.dbf,sql statement:
SELECT * FROM [T1] or select * FROM [T1.DBF]

3. Warehousing operation of various types of data
DBF is not supported by a lot of data types, which is worth noting date (date), Memo (Memo type), General (universal type). Here is a description of the data type, memo and Gen are used when storing graphics files, as described later in this article.
I generally use two ways to write a library operation, one is using the INSERT statement, one is using the AddNew method, for the DBF table, the two ways slightly different.
When using INSERT statements, be aware that the writing format for date data is {^YYYY-MM-DD}, which is different from the # of access and SQL Server. The specific SQL statement is:
insert INTO [t1.dbf] (Name,birthday) VALUES (' MyName ', {^1970-1-1})
When using the AddNew method, the code I used originally was:

Rst.open "[T1]", conn,0,3
Rst.addnew
RST (0). Value = "MyName"
RST (1). Value = {^1970-1-1}
Rst.update
Rst.close

There were no problems with SQL Server and access, but there was a problem with the DBF file operation. After the experiment, finally found the right way:

sql = "SELECT * from T1"
Rst.open sql,conn,0,3
Rst.addnew
RST (0). Value = "MyName"
RST (1). Value = {^1970-1-1}
Rst.update
Rst.close

Notice the difference between the above two pieces of code, mainly on the SQL statement. As mentioned earlier, in SQL statements, you can declare a table file in the form of table name or table name. DBF, but when you use the AddNew method, the table name does not have an extension, and you cannot add square brackets, otherwise you will be prompted for "not simple table name, not updatable."

4. Storage of graphics files
In DBF tables, Memo and general fields can be used to store graphics, audio, text, and other files (refer to http://www.chinadesign.com.cn/NewsContents1.asp?id=2663). Here, we set the field type to Memo (binary) (binary preparation type), using RST (n). The AppendChunk () method writes the resulting picture binary data, using the Response.BinaryWrite () method to restore the binary data to a picture. A lot of related articles in the picture warehousing, this no longer repeat.
As for the use of general (universal) fields to store pictures, I tried, did not succeed, also did not try again.

5. Deletion of data
You can use the DELETE statement to delete data, but when you delete it, you open the table file and find that the data is just a delete tag and is not actually deleted from the table. In FoxPro, you want to permanently delete data by using the Pack command. Checked some data, said that VB can not implement pack operation, the VBS of course more can not be achieved. The general solution is to import the data from the table (and, of course, unmarked deletions) into a new table at regular intervals, delete the original table, and then rename the table to the original table name.

6. Data and pictures at the same time storage
This issue does not belong to the scope of this article to discuss, there are many articles on the internet to solve the solution, incidentally, here.
I am using the "transformation" no component upload program to achieve this function. Some friends will ask, "transformation" upload is written as a file, there is no storage method AH. Yes, but a little change, you can get the binary data of the picture, and then the storage can be. In my example, the parts of the Transformation program change are commented, please refer to.

Four, the conclusion
This article mainly discusses the ASP to the DBF free table operation, if is the DBC library, in the example inc/conn.asp has given the corresponding connection string.
At this point, I believe that friends of the DBF table operation has a general understanding, combined with my example, I believe you can develop more functions.
Good luck!



Related Article

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.