开发者

Delphi: Creating Access DB (.mdb) without Ms Access

开发者 https://www.devze.com 2023-01-22 02:05 出处:网络
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).开发者_运维百科

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

0

精彩评论

暂无评论...
验证码 换一张
取 消