Results 1 to 4 of 4

Thread: How do I convert a dbf file to a text (.txt) file?

  1. #1

    Thread Starter
    Lively Member Christhemist's Avatar
    Join Date
    Sep 2016

    How do I convert a dbf file to a text (.txt) file?

    I'm trying to do this in vb.net and I'm not really seeing anything around the web on how to do this, any help would be greatly appreciated!

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005

    Re: How do I convert a dbf file to a text (.txt) file?

    By dbf file do you mean a database file... maybe DBase? If so there is no direct way that I know you need to select the data from the tables and write it out to a file
    Sometimes the Programmer
    Sometimes the DBA


  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Southern Tier NY

    Re: How do I convert a dbf file to a text (.txt) file?

    I'm not a database person so I assume there is probably a simple way to open the file using some type of data base access and then write the data out.

    It just so happens that even though I'm not a database person, in the last couple of weeks I was looking around for information on the format of a dbase IV version 5 format file because I was interested in trying to read shape (.shp) files. And while you can read a .shp file, it is just a collection of different types of shapes. To know what the parts of the shape mean you have to read a .dbf file that has a record for each "shape" in the shape file describing some attributes of the shape.

    Doing a google search the first hit I got was for a version 7 format, and once I figured out by looking at the file structure in a hex dump that version 7 wasn't what I wanted I searched again and found the description of version 5 and earlier.
    Of course as an early quick check I just dropped the .dbf file on an excel spreadsheet and it displayed the data (for the version 5 files I had) fine.

    I then proceeded to write code to manually parse the data from the file, knowing the format of the file. Of course the code is not generic as it is parsing the data and only looking at one field of each record (a road/path type from OpenStreetMap), which is not very useful as a general .dbf reader.

    The following link, http://web.archive.org/web/201503230...Fstruct.htm#C4, is the main one I used to identify and pull the data from once I read the data in as a byte array.

    I'm sure a real database person would shudder at the though of reading and parsing the bytes of the file in software, so if you need assistance opening the file and getting the data through normal database access methods, hopefully one of those persons will jump in if you ask.
    Last edited by passel; Dec 14th, 2016 at 12:55 PM.

  4. #4
    Lively Member
    Join Date
    Sep 2013

    Re: How do I convert a dbf file to a text (.txt) file?

    I have built many systems that use a .DBF (DBase 3/5) file system. From my experience you have several choices:

    1. If you have access to MS Office 2000 or 2003, you can open a .DBF file directly in Excel and then export it as a comma delimited (.CSV) file or as a fixed width file (.TXT).

    2. Using a SQL Query tool such as WinSQL Lite (which is free; a fantastic tool; I have used it for 20+ years against every database I have ever encountered), create an ODBC DSN using "Microsoft dBase Driver (*.dbf)" as the driver type, select "dBase 5.0" as the version, then select the directory where the *.DBF files reside. Open the SQL tool and do a "SELECT Field(s) FROM TableName WHERE ?????", then copy the results to Excel and export in the desired format.

    3. For a programmatic approach, connect to the database using the string "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\FolderName;Extended Properties=DBASE III". FolderName is the folder where the *.DBF files reside. (This was done using ADODB but I suspect ADO.NET would also work.) Select rows/fields from the desired table using the WHERE criteria desired, then read the rows one at a time and write to a text using CSV or TXT format.

    In the 20+ years I have been building database system, I have not come across a method in Visual Basic that allow a simple export to a text file. There are third party tools (for various prices) that might offer that type method.

    Hope this helps.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width