Delphi:创建Access数据库(.mdb)而不使用Ms Access
问题描述:
有没有办法创建Access数据库(.mdb)而不实际使用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).
我正在使用Delphi 5 Ent。
I'm using Delphi 5 Ent.
提前感谢! : - )
Thanks in advance! :-)
答
如果您使用ADOX库,是否有一种方法。它是一个可以在Delphi中导入的ActiveX库。然后,您可以使用下面的代码创建一个新的数据库。请参阅此处。
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;