#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    12
    Rep Power
    0

    [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,
    ~Perran
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    12
    Rep Power
    0
    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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    12
    Rep Power
    0
    I have solved this. I used SQL:

    ADOQTable1.Close;
    ADOQTable1.SQL.Clear;
    ADOQTable1.SQL.Add ('ALTER TABLE MyTable ADD COLUMN [' + mystring + '] YESNO');
    ADOQTable1.ExecSQL;

    thanks anyway!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Originally Posted by Perran
    I have solved this. I used SQL:

    ADOQTable1.Close;
    ADOQTable1.SQL.Clear;
    ADOQTable1.SQL.Add ('ALTER TABLE MyTable ADD COLUMN [' + mystring + '] YESNO');
    ADOQTable1.ExecSQL;

    thanks anyway!
    This will work, but if you're adding the column via a button press, what prevents the user from pressing it twice (or more)?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    12
    Rep Power
    0
    It doesn't matter because the string that it uses for the column name changes every time.

IMN logo majestic logo threadwatch logo seochat tools logo