Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CREATE DBF FROM DELIMITED FILE

Status
Not open for further replies.

acorbally

Programmer
Jan 9, 2001
65
US
I have looked over other posts and don't find my answer. I am trying to take a csv file and create a foxpro 2.6a dbf file from it. I tried the following and am getting an error. I don't see what I am missing

Command: IMPORT FROM MODE_CD
Error: Required clause not present in command.

Any thoughts?
 
You have to create the .dbf file to hold the data before you can import it.
You will need to know the length of each field and the data type, then you can do something like:
CREATE MyTable
APPEND FROM MODE_CD DELIMITED

Another option you may try is to import the data into Excel, then export (Save As) it as a .dbf.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Thanks. The help reads:
Import Command: Imports data from an external file format to create a new FoxPro table. That sounds like to me that is was creating the table for me. As for your second option, I would like to keep this as independent from the user as possible. Can you do it all without user intervention?
 
You are correct, but the reason you are getting the syntax error is that you haven't specified a file type. You'll note that the CSV format isn't listed in the list of file types that IMPORT supports. Note: That all the IMPORT types have the field size and type information available in the file format!

What Dave was pointing out, is that the APPEND does support CSV file types, but FoxPro has to know the number and type of fields before it can do this. (Hence the reason you need a table defined first.)

The only alternaitve to a generic situation as you've outlined, would be to open the file using low-level IO (FOPEN, FGETS, FREAD, etc.). Then you could parse the first record to get the field names. Next you'd have to "look" at the next 'n' data records, and try to determine the field types and lengths. Then you could create a table and use the APPEND.

What's creating the CSV file? Can't you get the output in another format?

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top