Subject Re: modify table structure in program
From Mervyn Bick <invalid@invalid.invalid>
Date Sun, 6 Mar 2022 10:58:37 +0200
Newsgroups dbase.getting-started

On 2022/03/06 00:15, Charlie wrote:
> Hi...   I am importing a csv file by 'save as' a dbase table.  But I only have four fields in the csv file and I need to modify the table before opening the form with grid which specifies more fields.  As I understand 'save as' overwrites the table losing all structure.  Wondering if there is a way to add and modify fields using a program rather than manually modifying the structure?
>
> Thanks for any help.

As Ken has pointed out the localSQL command ALTER TABLE, which can be
used in a little program, will add (or drop) fields from a table.
Details are in the dBASE help file. This will, however only add fields
after the existing fields in each record.  If you need the extra fields
interspersed between the four fields from the .csv file it can be done
but it needs an additional step using the SAVE TO option of the SELECT
command.

The 'save as' suggests you are reading the .csv file into a spreadsheet
(perhaps Excel) and then saving to a .dbf file.  This is all very well
for dealing with an occasional .csv file.  If, on the other hand, you
have to deal regularly with similar data in a .csv file it is far more
productive to write a simple little program to import the .csv directly
into a .dbf file.

If you post the structure of the .dbf file your grid needs and show
which fields need the data from the .csv file I can give you a little
example program.

It will help if you can also provide a .csv file with, say, 5 records.
If the information is confidential then give details of how dates,
timestamps or logical values (if any) are presented in the .csv file.

Would you want to create a separate .dbf for each .csv file or would you
want to append each .csv file to an existing .dbf file?

Mervyn.