Re: Add field to ADOTable and a Column for a tDbGrid at runtime
- From: "Guillem" <guillemvicens-nospam@xxxxxxxxxxxxxxxxxx>
- Date: 23 Oct 2006 03:16:51 -0700
Pablo Romero wrote:
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
If you have your dataset connected through an ADOConnection to the
database, I think Daniel is right.
Try this instead (once you've created the field in the database),
ADOTable.DisableControls;
ADOTable.Close;
ADOTable.CommandText := YourSQLSentence;
//other processing you may be doing
ADOTable.Open;
ADOTable.EnableControls;
--
Best regards :)
Guillem Vicens Meier
Dep. Informatica Green Service S.A.
www.clubgreenoasis.com
--
Contribute to the Indy Docs project: http://docs.indyproject.org
--
In order to contact me remove the -nospam
.
- References:
- Add field to ADOTable and a Column for a tDbGrid at runtime
- From: Pablo Romero
- Add field to ADOTable and a Column for a tDbGrid at runtime
- Prev by Date: Re: TADODataset.Filter?
- Next by Date: Re: ADO vs dbExpress
- Previous by thread: Re: Add field to ADOTable and a Column for a tDbGrid at runtime
- Next by thread: TADODataset.Filter?
- Index(es):