This is the program code for adding fields to the table, but it adds the field only after restarting the program.

Table1.Active:=False; Query2.Close; Query2.Sql.Clear; Query2.Sql.Add('alter table '+Edit4.Text+' add '+Edit2.Text+'char(20)'); Query2.execSQL; DBGrid1.Columns.Add; Table1.Active:=False; end; 
  • 2
    @vaska, the code adds the field immediately. Please describe your problem in more detail. In what place and at what point in time do you expect to see changes, and what do you do for this (reopen the query, re-create the table, etc.). - Yura Ivanov

2 answers 2

If you didn’t manually add fields to Table1 (double click on the component - - add all fields), then this option will probably work.

 Query2.Sql.Text := 'alter table '+Edit4.Text+' add '+Edit2.Text+'char(20)'; Query2.execSQL; Table1.Refresh; 

or

 Table1.Refresh; DBGrid1.Columns.Clear; DBGrid1.Columns.Add; 

PS: You can also use EnableControl / DisableControl - the application will not flicker when rebuilding data. And this should all be done in a try-finally block.

    In the last line

     Table1.Active := True; 

    Not?