Plurk

使用Delphi 壓縮 Access DB

網路上找來的, 原來還蠻簡單, 以前一直沒去想, 突然用上, 找來頂一下!

function compressDB(dbName: string): Boolean;
var DaoVar: OLEVariant;
begin
 if ADOConn.Connected then ADOConn.Close;
 try
  try
   DaoVar := CreateOleObject('DAO.DBEngine.36');
   if FileExists('temp.mdb') then DeleteFile('temp.mdb');
   DaoVar.CompactDatabase(dbName, 'temp.mdb');
   if DeleteFile(dbName) then RenameFile('temp.mdb', dbName);
   ShowMessage('Success');
   Result := true;
  except
   Result := false;
  end;
 finally
  ADOConn.Open;
 end;
end;

0 意見:

Designed by Posicionamiento Web | Bloggerized by GosuBlogger | Blue Business Blogger