Add field to ADOTable and a Column for a tDbGrid at runtime



Hi Fellas:

I have a little problem.

I need to add a field to a MS SQL Table at run-rime.

I did

ADOtable.close;
ADOCommand.CommandText := 'ALTER TABLE Empleados ADD COLUMN Notas
TEXT(25)';
ADOCommand.Execute;
ADOTable.Open;

Ok, the field is added.

Now i want to use that field in my program. So I Did:

with ADOTable do
begin
Close;

FieldDefs.Update;

for i := 0 to FieldDefs.Count - 1 do

if FindField(FieldDefs[i].Name) = nil then

FieldDefs.Items[i].CreateField(ADOMyTable);

F := TStringField.Create(ADOMyTable);
F.FieldName := 'myField';
F.DisplayLabel := 'myFieldLabel';
F.name := 'ADOmyNewField';
F.DataSet := ADOMyTable;
F.Size := 30;
Fields.Add(F);
open;
end;

Ok, the field is created.

Now I want to add this field to a column for a TDbgrid that is shown at this
time

The grid is showing the 3 fields that my ADOTABLE has. I added a 4th.

When I add the field to the Dbgrid using the 'tcolumn' object and the 'add'
method, the grid changes and shows one column, the lastest, the new.

Any ideas, please?

Regards.

Pablo Romero


.