Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...The enviroment is simple, natural and efficient. The members are competent, educated and professionals..."

Geography

Where in the world do Tek-Tips members come from?

.DBF file header (number of records) not being updated

qkumbr (Programmer)
19 Jan 09 13:41
I am using VB to write an application that queries and updates .DBF files.

There's a 4-byte header (offsets 4-7) in a .DBF indicating how many records are in the file. See here: http://www.dbf2002.com/dbf-file-format.html

When I do an SQL "INSERT INTO" statement, this header is updated correctly.

When I do "DELETE FROM", the header isn't even touched.

Example: I insert 1000 records into a table. The header shows 1000 records. When I remove all 1000 records, the header still shows 1000. A "SELECT COUNT(*)" statement returns a value of 0.

If I open the .DBF in Excel (I don't have Visual FoxPro) and simply save it, the header is updated correctly.

Anyone familiar with this? Here's a snippet of my code when I'm doing a delete:

Dim Conn = CreateObject("ADODB.Connection")
Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & datapath & ";Extended Properties=DBASE IV;")
Conn.execute("DELETE FROM table WHERE somerecord = somevalue")
Conn.close()

TIA
dbMark (Programmer)
20 Jan 09 10:42
After you have used the SQL code to delete the records, is the actual DBF file size smaller?  I suspect not.

The way a DBF table is designed and structured is that it can contain both active and deleted records.  When you delete a record it is just flagged as deleted and is still there.  This makes it possible to RECALL a deleted record and not lose it's data.  It is only when the table is PACKed that the actual records marked as deleted that the records are removed , the file is smaller and the record count or RECCOUNT() is reduced.

The flag for the deleted record is an asterisk placed in the first true field of the record segment in the table.  For example, say you have a table with 2 fields and each is 10 characters long.  When you add a record, the table will actually be 21 bytes longer (1+(2*10)) ... 1 byte for the deletion flag and 20 bytes for the to fields.  Normally the delete flag is blank (a space, character 32) but when deleted the record is updated with an asterisk (*) in that flag.
JCreamerII (MIS)
20 Jan 09 14:49
TIA,

Mark is correct.  If you haven't "PACK"ed the DBF after the delete, the counts wouldn't change.   The records noted should be marked for deletion and need to be packed out to remove them completely.

Jim C.  
 
qkumbr (Programmer)
23 Jan 09 11:29
Not sure how to pack my tables, though. I've searched high and low and I'm coming up with nothing. Only way I know how to do it is open/save in Excel. Thanks again.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close