Board index » delphi » Create New ADOX Catalog

Create New ADOX Catalog

How can I create an MS Access database via ADO. All the documentation I can
find deals with DBs that are already created.  Microsoft documents how to do
it in VB, but I am having trouble translating that to Delphi 5. The
Microsoft document is at
www.microsoft.com/data/ado/adotechinfo/dao2ado_4.htm

It looks pretty easy in VB so I'm sure it will be easier for D5, just not
easy for me.

--
______________________________
Agency Business Systems, Inc.
e-mail: sa...@agencybusys.com
web:   http://www.agencybusys.com

 

Re:Create New ADOX Catalog


Use the code below as a template:

procedure TForm1.Button1Click(Sender: TObject);
var
 Catalog  : _Catalog;
 Table    : _Table;
 BaseName : String;
 DS       : String;
begin
 BaseName := 'd:\data\demo.mdb';

 Catalog :=
  CreateCOMObject(StringToGUID('ADOX.Catalog')) as _Catalog;

 DS := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+BaseName;

 If FileExists(BaseName) Then DeleteFile(BaseName);

 Table :=
  CreateCOMObject(StringToGUID('ADOX.Table')) as _Table;
 Table.Name := 'Customers';

 Catalog.Tables.Append(Table);

 Table.Columns.Append('FIRSTNAME', adVarWChar, 128);
 Table.Columns.Append('LASTNAME',  adVarWChar, 128);

end;

Note that first you need to export the ADOX type library. To do so, choose
Project | Import Type Library
command from the main menu and in the Import Type Library dialog box select
Microsoft ADO Ext. 2.1
for DDL and Security (Version 2.1). After that you will get the ADOX_TLB
unit, that should be included
in your USES clause.

--
Best regards,
Alex Fedorov
afedo...@aha.ru

Quote
Homer <supp...@agencybusys.com> wrote in message

news:7uem09$l612@forums.borland.com...
Quote
> How can I create an MS Access database via ADO. All the documentation I
can
> find deals with DBs that are already created.  Microsoft documents how to
do
> it in VB, but I am having trouble translating that to Delphi 5. The
> Microsoft document is at
> www.microsoft.com/data/ado/adotechinfo/dao2ado_4.htm

> It looks pretty easy in VB so I'm sure it will be easier for D5, just not
> easy for me.

> --
> ______________________________
> Agency Business Systems, Inc.
> e-mail: sa...@agencybusys.com
> web:   http://www.agencybusys.com

Re:Create New ADOX Catalog


Thanks for the simple example to those of use new to ADO. However I get an
error " The object referenced by the application no longer points to a valid
object" when Delphi executes  "Catalog.Tables.Append(Table)" in your
example. What am I missing?

Thanks,
Ivan

Other Threads