Delphi: Creating Access DB (.mdb) without Ms Access
Is there a way to create Access databases (.mdb) without actually using Ms Access? I'd like my app to create it instead (when user presses "New Document" on the toolbar).开发者_运维百科
I'm using Delphi 5 Ent.
Thanks in advance! :-)
Yes there is a way if you use the ADOX library. It is an ActiveX library you can import in Delphi. Then you can create a new database with the code below. See here.
procedure TForm1.btnNewDatabaseClick(Sender: TObject);
var
DataSource : string;
dbName : string;
begin
dbName:='c:\aboutdelphi.mdb';
DataSource :=
'Provider=Microsoft.Jet.OLEDB.4.0' +
';Data Source=' + dbName +
';Jet OLEDB:Engine Type=4';
ADOXCatalog1.Create1(DataSource);
end;
This is how it's done:
procedure CreateNewDatabase;
var
AdoxCatalog: Catalog;
begin
AdoxCatalog := CoCatalog.Create;
AdoxCatalog.Create(ConnectionString
+ 'Jet OLEDB:Engine Type='+IntToStr(Jet4x)+';');
end;
You will need ADOX_TLB which you can get by importing type library "Microsoft ADO Ext. 2.8 for DDL and Security".
精彩评论