Adding a Field to a Table using code.

A

Allen Browne

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top