How to Modify a Table's Structure Programmatically in FoxProID: Q135320 The information in this article applies to:
SUMMARYThis article shows by example how to change the structure of a data table programmatically.
MORE INFORMATIONModifying the structure of a pre-existing data table in FoxPro is not possible in the run-time environment because the Modify Structure command is not supported. To modify a table structure, you must: 1. Copy the structure into an array or interim table. 2. Modify the particular element or field. 3. Create a table from this changed array or table.
Sample CodeFollowing is sample code that creates a table programmatically and copies its structure to an array. It then changes the length of one of the fields, and creates a table from the edited array. * Create Table myTable CREATE TABLE myTable; INSERT INTO myTable VALUES("Eric","Cardenas","Sydney")
LIST STRUCTURE
LIST
COPY TO myTemp
* Store structure into an array =AFIELDS(arrTable) Change length of first_name to 30 arrTable[1,3] = 30 setSAFETY = SET("SAFETY") SET SAFETY OFF CREATE TABLE myTable; APPEND FROM myTemp
LIST STRUCTURE
LIST
SET SAFETY &setSAFETY
Using the COPY STRUCTURE EXTENDED CommandIf you want to add or delete a field, it may be useful to us the COPY STRUCTURE EXTENDED command, and then work with the structure .DBF file. The COPY STRUCTURE EXTENDED command makes a table that has four fields: Field_name, Field_type, Field_len, and Field_dec. Each record of the table corresponds to a field in the original table.
Step-by-Step Example1. Create a table named Test with the following format:
2. Save the changes, and enter two or three records. The actual data is not
3. Create the following program:
4. Run this program, and browse the Newstruc table. Notice that the field
5. Remove the comment asterisk from the last four lines of code if you want
Additional reference words: FoxWin 2.60a structure modifying
KBCategory: kbprg kbcode
KBSubcategory: FxprgTable
|
|
Last Reviewed: August 22, 1995 © 1999 Microsoft Corporation. All rights reserved. Terms of Use. |