Board index » delphi » Create new fields in a MS Access db via ado

Create new fields in a MS Access db via ado

I have a access db and need to create some new fields in it and I'm having
some trouble.  Here is what I'm doing, whats working and whats not:

1.  Using A ADOQuery component with sql:

      Alter table MyTable Add Column NewField {Type}

*     If FType = 'Integer'    then SQL.Add('ADD COLUMN '+FNAME+' Integer');
*    If FType = 'String'     then SQL.Add('ADD COLUMN '+FNAME+' String
('+Width+')');
*    If FType = 'Text'       then SQL.Add('ADD COLUMN '+FNAME+' String
('+Width+')');
*    If FType = 'Memo'       then SQL.Add('ADD COLUMN '+FNAME+' Memo');
*    If FType = 'Currency'   then SQL.Add('ADD COLUMN '+FNAME+' money');
      If FType = 'Date'       then SQL.Add('ADD COLUMN '+FNAME+' Datetime
Null');
      If FType = 'Boolean' then SQL.Add('ADD COLUMN '+FNAME+' bit Null');

* worked.   I couldn't get the Date and Boolean fields to create no matter
what I did.  Any help would be greatly appreciated.

Thanks,
Ed

 

Re:Create new fields in a MS Access db via ado


Located a link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnac...
l/acintsql.asp

Thanks,
Ed

Re:Create new fields in a MS Access db via ado


Quote
>    If FType = 'Boolean' then SQL.Add('ADD COLUMN '+FNAME+' bit Null');

>* worked.   I couldn't get the Date and Boolean fields to create no matter
>what I did.  Any help would be greatly appreciated.

Where are you getting the FTtype value from?
Are you sure you its not getting set to 'DateTime' for date fields?

For boolean fields try leaving of the NULL
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Create new fields in a MS Access db via ado


"Brian Bushay TeamB" <BBus...@Nmpls.com> wrote in message
news:ic94gu4ug1tbeh3i58kbosf1objscbinj5@4ax.com...

Quote

> >    If FType = 'Boolean' then SQL.Add('ADD COLUMN '+FNAME+' bit Null');

> >* worked.   I couldn't get the Date and Boolean fields to create no
matter
> >what I did.  Any help would be greatly appreciated.

> Where are you getting the FTtype value from?
> Are you sure you its not getting set to 'DateTime' for date fields?

> For boolean fields try leaving of the NULL

Is this one of those silly Access/external ADO v Access/internal DAO issues?
I successfully just ran the following queries inside Access 2000:

ALTER TABLE Table1 ADD COLUMN aBoolean BIT NULL
ALTER TABLE Table1 ADD COLUMN aDate DATE NULL
ALTER TABLE Table1 ADD COLUMN aDate DATETIME NULL

--

Quidquid latine dictum sit, altum videtur.
#319

Re:Create new fields in a MS Access db via ado


Hi DRS,

Quote
> ALTER TABLE Table1 ADD COLUMN aBoolean BIT NULL
> ALTER TABLE Table1 ADD COLUMN aDate DATE NULL
> ALTER TABLE Table1 ADD COLUMN aDate DATETIME NULL

I just tried the same thing from within Delphi with a TADOCommand and it works
fine.
As Brian suggested, the problem is probably with the FType value.

Thrse

Re:Create new fields in a MS Access db via ado


Tanks for the help,

Ed

Other Threads