The information in this article applies to:
SUMMARY
The following passage appears in the "Professional Features," Book 2,
page 141:
dBASE and FoxPro database systems do not physically delete records, but merely mark them for deletion at a later time. You must pack the .DBF file (using your own utilities) to remove these records from the .DBF files. The CompactDatabase function will not affect attached tables. This article shows you how to ZAP and/or PACK a dBASE or FoxPro table in Microsoft Visual Basic version 3.0 without needing separate utilities. MORE INFORMATION
To be able to ZAP or PACK your .DBF files, you must have the following
entry in your VB.INI or <appname>.INI file:
This will filter out deleted records so they do not appear in recordsets. To perform a ZAP, you simply need to run a DELETE action query. For example, the following sample marks all the records in the AUTHORS.DBF table as deleted:
NOTE: For extremely large tables, it is more efficient to delete the Tabledef representing the table from the TableDefs collection of the database and then re-create the table structure. Please see articles Q110959 and Q108147 for more information on this approach. The following subroutine shows you how to perform a PACK. Essentially, you copy all the records to a new temporary table, delete the old one, then rename the temporary table as the original name. Sample Code
The following example code shows you how to call the above subroutine. First, you open the database the table is in, then you pass the database object and the name of the table to PACK to the subroutine. Be sure that there are not any open recordsets on the table you are trying to pack or you will get an error.
NOTE: The above methods do not preserve formatting of numeric fields for our dBASE and FoxPro tables. To work around this limitation you should keep a template DBF file created from dBASE or FoxPro that contains the formatting you need, and use an INSERT INTO statement instead of the SELECT INTO statement shown above. Additional query words: 3.00
Keywords : |
Last Reviewed: June 25, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |