Adding a Field to a Table using code.

  • Thread starter Thread starter Guest
  • Start date Start date
Method 1: DDL
Execute a query statement such as:
"ALTER TABLE MyTable ADD COLUMN MyColumn TEST;"
"ALTER TABLE MyTable DROP COLUMN MyColumn;"

Method 2: DAO
Use CreateField() and then Append to the Fields collection of the TableDef.
Delete the Field from the Fields collection of the TableDef

Method 3: ADOX
Declare a new ADOX.Column, and Append to the Columns of the Table.


Use method 1 for a quick and simple approach.

Use method 2 if you want fine control over the properties of the new field.

Use method 3 if you are a maschochist. (ADOX is very buggy, with different
bugs in different versions so you never know what you will end up with.)
 
Back
Top