access中有没有语句可以压缩数据库?(50分)

S

songhb

Unregistered / Unconfirmed
GUEST, unregistred user!
有一个access数据库,将其中所有数据都删除,还有30多M,
执行access2000菜单中的压缩数据库命令后,只有100多k了,
那么我能不能在access中执行语句来压缩,而不用菜单命令压缩?
 
在access中执行语句??? 我不知道 ,下面是在delphi中的语句
Var
Compact:DBEngine;
strSrc,strTarge:String;
begin
//
Data.QueryMain.Close ;
Data.DBCode.Connected := False ;
Compact := CoDBEngine.Create ;
strSrc := AppPath + 'ProgramSource.mdb' ;
strTarge := AppPath + 'CompactBak.mdb' ;
Try
CopyFile(Pchar(strSrc),Pchar(strTarge),False);
Try
strTarge := AppPath + 'CompactTemp.mdb' ;
Compact.CompactDatabase(strSrc,strTarge,'',0,'');
DeleteFile(strSrc);
RenameFile(Pchar(strTarge),Pchar(strSrc));
Except
Application.MessageBox(Pchar('数据库压缩失败!'),Pchar('提示'),MB_OK+MB_ICONSTOP);
strTarge := AppPath + 'CompactBak.mdb' ;
RenameFile(Pchar(strTarge),Pchar(strSrc));
End;
Application.MessageBox(Pchar('数据库已压缩,请重新运行本程序!'),Pchar('提示'),MB_OK+MB_ICONINFORMATION);
Except
Application.MessageBox(Pchar('数据库压缩失败!'),Pchar('提示'),MB_OK+MB_ICONSTOP);
End;
Application.Terminate;
end;
 
试试这段代码:
procedure Tfm_main.Compact;
var dao:OLEVariant;
begin
adoconnection.Close;
screen.Cursor:=crHourGlass;
dao:=CreateOleObject('DAO.DBEngine.36');
dao.CompactDatabase(getcurrentdir+'/database.mdb',getcurrentdir+'/new.mdb');
DeleteFile(getcurrentdir+'/data.mdb');
RenameFile(getcurrentdir+'/new.mdb','database.mdb');
adoconnection.Open;
screen.Cursor:=crDefault;
application.MessageBox('成功压缩数据库','提示',mb_ok+mb_iconinformation);
end;
 
pack就好!
 
同意locka
此问题原来有多地有详细说明,查一下可节省分数
 
多人接受答案了。
 
顶部