February 19th, 2013, 05:07 AM
[solved] Adding a Column/Field to an ADOTable
I have an ADOTable1 which is connected to an ms access table and I want to add a field/column to the ADOTable.
I have read other forum posts but haven't managed to get it to work.
I need to add a yes/no field and a number field.
Thanks in advance,
February 19th, 2013, 08:48 AM
I'm not sure I understand what the actual question is. If it's about how to add the fields to your Access database, I would highly recommend that you do that through Access, not through your program. Adding the columns is a one time event, so once it's added, you wouldn't need to run that code ever again. Kind of a waste to code it, only to run it once, when using Access itself is so much easier.
As far as having Delphi "see" the changes, it does so, but you will need to take into consideration your query's actual SQL and which fields were added in the field's editor.
If your SQL iterates the actual columns you want to return Select <column1>, ... versus select *, then you will need to add the new columns to the select list i.e. Select <column1>, ..., <newcolumn1>, <newcolumn2> from ...
To add the new fields to the fields editor, double click on the table or query component, right click in the field's editor and select add all fields. Any new fields will be added.
February 20th, 2013, 06:05 AM
I need to add a field to the ADOTable in code so that the user can add a field by pressing a button so that they don't have to create one in access and program it in.
February 20th, 2013, 08:50 AM
I have solved this. I used SQL:
ADOQTable1.SQL.Add ('ALTER TABLE MyTable ADD COLUMN [' + mystring + '] YESNO');
February 20th, 2013, 08:54 AM
This will work, but if you're adding the column via a button press, what prevents the user from pressing it twice (or more)?
Originally Posted by Perran
February 22nd, 2013, 08:39 AM
It doesn't matter because the string that it uses for the column name changes every time.