Can anyone tell me how to add and delete fields in a table at runtime??
It shows how to add fields and thier definitions ...
procedure TForm1.FormCreate(Sender: TObject);
//Create database if file doesn't exist
if NOT FileExists(ExtractFilePath(Application.ExeName)+'MYDB.DB') then
MessageDlg('No Database Found'+#10#10+'Creating new database',
mtInformation, [mbOK], 0);
with Table1 do
//Make sure the table is NOT active
Active := False;
//Set DatabaseName to executable files path
DatabaseName := ExtractFilePath(Application.ExeName);
//Set TableName to your required name
TableName := ExtractFilePath(Application.ExeName)+'MYDB.DB';
TableType := ttParadox;
with FieldDefs do
//Set 1 field of type string, 60 chars long, required true for
//Some example field types you could add
with IndexDefs do
//The default Primary Index
Add('Ascending', 'NotesField', [ixPrimary,ixUnique]);
//The Secondary Index
//Create your table
//Now its created you can open it
//Add a couple of entries just to see what happens
Table1.AppendRecord(['A first entry']);
Table1.AppendRecord(['B second entry']);
Table1.Open; // Now open your new database for viewing
Hope that helps!
> Can anyone tell me how to add and delete fields in a table at runtime??
Try to use simple ExecSQL method, and in SQL string type the Desired
SQL command at design time, or this SQL command can even be made at
runtime. It works on SQL Databases, but I am not sure of XBases.
Please feel free to get the source listing, in case you face any
Thanks, with Warm Regards!
Pie-MESON Systems & Softwares
Authorised Developer Partners for Borland Products
I am trying to add a field to a table programmatically, ( I have to
support customers and can't update their tables manually, too much work)
This is what I have tried.
ALTER TABLE "c:\MYDATABASE\MYTABLE.DB"
ADD FIELDNAME TYPE
This work ok as long as the fieldname does not include spaces. In
paradox tables (which I am using) spaces in the name is legal.
I tried to surround the name by double quotes " and by single quotes '
this did not work. What I get is the following error:
INVALID USE OF TOKEN VARCHAR(10): Line number 2
How do you add a field with the SQL Statement Alter Table in which the
field name has spaces?. Also what is the appropriate type for Currency
Thanks in advance
Jose R. Nebro
6. VB & ASP