如何压缩access数据库(50分)

  • 主题发起人 主题发起人 sherman
  • 开始时间 开始时间
S

sherman

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在使用dao(diamond)连接ACCESS数据库,如何压缩数据库
 
看看Diamond的例子,一个很简单的压缩Access的语句,直接使用DAO的
API就可以了。查查以前的问题,我记得我回答过一个这样的问题。
 
我就是要这个API函数的名称和用法,我也知道调用__DBEngine。
 
下面是用VBA的
http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=253003
 
var
DaoObject:OleVariant;

try
DaoObject:=GetActiveOLEObject('DAO.DBEngine.35');
except
try
DaoObject:=GetOLEObject('DAO.DBEngine.35');
except
DaoObject:=null;

DaoObject.CompctDataBase(FileName,TempFile);
 
function CampactAccessDB(const FileName: String):Boolean;
var
db:OLEVariant;
tempfile:String;
begin
Result:=False;
try
Screen.Cursor:=crHourGlass;
try
tempfile:=AppendSlash(ExtractFilePath(FileName))+'AccessTemp.mdb';
db.CompactDatabase(FileName,tempfile);
DeleteFile(FileName);
RenameFile(tempfile,FileName);
Result:True;
except
on E:EOleException do
MsgError(E.Message);
end;
finally
db:=Unassigned;
Screen.Cursor:=crDefault;
end;
end;
 
我用的是 Diamond,能不能根据这个举例子
 
没有人知道__DBEngine的用法吗??
 
unit UMain;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, DAODatabase, DAOTlb;

type
TMainFrm = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
MainFrm: TMainFrm;

implementation

{$R *.DFM}

procedure TMainFrm.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
__DBEngine35.CompactDatabase (OpenDialog1.FileName, ExtractFilePath (OpenDialog1.FileName) + 'compacted.mdb', '', 0, '');
end;
end;

procedure TMainFrm.FormCreate(Sender: TObject);
begin
if __DBEngine35 = nil then CreateEngine (Dao35, '');
end;

procedure TMainFrm.Button2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
__DBEngine35.RepairDatabase (OpenDialog1.FileName);
end;
end;

end.
 
这是我程序中的一段代码
procedure TMainForm.N11Click(Sender: TObject);
var
mdbpath:string;
begin
mdbpath:=extractfilepath(application.exename);
daodatabase1.connected:=false;
if __DBEngine35 = nil then CreateEngine (Dao35, '');
__DBEngine35.CompactDatabase (mdbpath+'gz.mdb',mdbpath+'gz1.mdb' , '', 0, '');
deletefile('gz.mdb');
copyfile(pchar(mdbpath+'gz1.mdb'),Pchar(mdbpath+'gz.mdb'),false);
deletefile('gz1.mdb');
daodatabase1.databasename:='gz.mdb';
daodatabase1.connected:=true;
daotable1.open;
end;
 
多人接受答案了。
 
后退
顶部