Adding fields to existing ADO tables 
Author Message
 Adding fields to existing ADO tables

Hi,

I've been trying to dynamically add fields to an existing Access
database/table using ADO and Microsoft Jet as my provider, without
success. The table already contains some fields, and I desperately need
the ability to add more based on user input. Can anyone give me a hand
with this one?

Thanks a MILLION in advance,
Jason Peter Brown.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Tue, 10 Sep 2002 03:00:00 GMT  
 Adding fields to existing ADO tables

Look up ALTERTABLE SQL statement and CreateField.  These commands do what you're
after.

The example in ALTERTABLE is one of adding a field to a table.

Mianne.

Quote:

>|  Hi,
>|  
>|  I've been trying to dynamically add fields to an existing Access
>|  database/table using ADO and Microsoft Jet as my provider, without
>|  success. The table already contains some fields, and I desperately need
>|  the ability to add more based on user input. Can anyone give me a hand
>|  with this one?
>|  
>|  Thanks a MILLION in advance,
>|  Jason Peter Brown.
>|  
>|  
>|  Sent via Deja.com http://www.deja.com/
>|  Before you buy.



Tue, 10 Sep 2002 03:00:00 GMT  
 Adding fields to existing ADO tables

Quote:

> I've been trying to dynamically add fields to an existing Access
> database/table using ADO and Microsoft Jet as my provider, without
> success. The table already contains some fields, and I desperately need
> the ability to add more based on user input. Can anyone give me a hand
> with this one?

Well, you can use an ALTER TABLE statement(SQL), but I would not recommend it.
If you don't mind my saying so(I'm glad you don't *grin*) any time I get the
urge to dynamically create new fields in a table, I examine my data model VERY
carefully.  Usually, if I'm wanting to add new fields to an existing table on
the fly, something is not right in my data model.  Get a book on database design
before you proceed and read the chapters on normalization of data.

IE:  instead of having a table looking like this:
TABLE CUSTOMER
Firstname
Lastname
Street
City
Zip

and I want to add a field Phone Number, I would instead break it into 3 tables:

TABLE CUSTOMER
customerID

TABLE INFO_TYPE
infotypeID
infotype_description

TABLE CUSTOMER_INFO
customerID
infotypeID
value

This format allows me to add unlimited information types and unlimited
information about the customers, without modification to the underlying database
structure.

Just a thought.

--
 ----------------------------------------------------------------------------
|          Jeff Goslin - Monument           | "Oh Bentson, you are so        |

|                                           |  ravages of intellect."        |
|   http://www.acs.oakland.edu/~jggoslin    |   --Evil, The Time Bandits     |
 ----------------------------------------------------------------------------
|   how come everyone elses religion is a cult but your cult is a religion   |
 ----------------------------------------------------------------------------



Tue, 10 Sep 2002 03:00:00 GMT  
 Adding fields to existing ADO tables

Quote:

> Hi,

> I've been trying to dynamically add fields to an existing Access
> database/table using ADO and Microsoft Jet as my provider, without
> success. The table already contains some fields, and I desperately
need
> the ability to add more based on user input. Can anyone give me a hand
> with this one?

The response you got from Jeff Goslin has very good advice -- if you
need to add various fields dynamically it sounds like adding other
tables might be a more appropriate solution.

If you really do want to alter an existing table you can try the Alter
statement as suggested or you can use the ADOX object (something
like "Microsoft ADO Ext n for DDL and Security" in project/references)
See http://www.microsoft.com/data/ado/adotechinfo/dao2ado.htm
for comparisons between DAO and ADO including some examples of thi sort
of thing
--
Please reply via the newsgroup only

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 10 Sep 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to modified existing field and add new field in existing table for Access database

2. Create new field in existing table exactly like field in second table

3. Adding required fields with default values to existing tables

4. Adding new fields to an existing table

5. Adding Tables and Fields to an existing database

6. Add New Field in existing Table (VB6)

7. Adding required fields with default values to existing tables

8. Adding / Appending fields to existing table

9. Adding a new field to an existing table via ADOX

10. ADO: format rs!xxxxx when the field name exists in more than one table

11. How to add Tables/Fields with ADO?

12. Add fields to an Access 2000 Table on the fly using ADO 2.1

 

 
Powered by phpBB® Forum Software