谢谢!

解决方案 »

  1.   

    调用DAO,.压缩:
    dbengine.compactdatabase olddb,newdb,local,options,password.olddb,需要进行压缩整理的数据库文件名,。
    newdb,进行压缩整理后新的数据库文件名。不能与olddb相同。
    local可选,
    options 可选,。
    password,可选,如果原数据库有加密码,就需要写入,否则无法完成。修复:
    DBEngine.RepairDatabase ("" & txtRepair.Text)
    数据库文件名, txtrepair.text.
      

  2.   

    ADO: 
    回答:     你需要升级到VB 6SP3(QA001156 "VB中的sp2,sp3,企业版这三种各代表什么含义"),因为这个版本提供Jet 4.0支持在ADO中使用CompactDatabase。例子: 
        1、在IDE中选择“工程|引用”菜单。 
        2、添加Microsoft Jet and Replication Objects X.X library(这里X.X是大于或等于2.1的数)。 
        3、使用如下代码: 
         Dim jro As jro.JetEngine 
         Set jro = New jro.JetEngine 
         jro.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\nwind2.mdb", _ 
         "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\abbc2.mdb;Jet OLEDB:Engine Type=4" 
         
        Owen的意见: 
        Delphi版本: 
        procedure TChechkCodefrm.FormClose(Sender: TObject; 
         var Action: TCloseAction); 
         
         Function CompactAndRepair(sOldMDB : String; sNewMDB : String) : Boolean; 
         const 
         sProvider = 'Provider=Microsoft.Jet.OLEDB.4.0;'; 
         var 
         oJetEng : JetEngine; 
         begin 
         sOldMDB := sProvider + 'Data Source=' + sOldMDB; 
         sNewMDB := sProvider + 'Data Source=' + sNewMDB; 
         try 
         oJetEng := CoJetEngine.Create; 
         oJetEng.CompactDatabase(sOldMDB, sNewMDB); 
         oJetEng := Nil; 
         Result := True; 
         except 
         oJetEng := Nil; 
         Result := False; 
         end; 
         end; 
        var 
         s: TStringList; 
         tmps: string; 
        begin 
         inherited; 
         LocalCon.Close; 
         tmps:='wg.mdb'; 
         if FileExists('CtwgClientcfg.ini') then 
         begin 
         s:=TStringList.Create; 
         s.LoadFromFile('CtwgClientcfg.ini'); 
         if s.IndexOf('[Data Source]')>-1 then 
         tmps:=s[s.IndexOf('[Data Source]')+1]; 
         end; 
         if CompactAndRepair(tmps, 'wg1.mdb') then 
         begin 
         DeleteFile(tmps) ; 
         RenameFile('wg1.mdb',tmps); 
         end; 
         LocalCon.Connected:=true; 
        end; 
        以上是我用的主个完整过程,可直接调用。 
        你要在uses中加入JRO_TLB,如编译找不到该文件,则在IDE->import type library中导入Microsoft Jet and Replication Objects 2.x Library[version 2.x],重新编译,应该OK了。
      

  3.   

    压缩:
    dbengine.compactdatabase olddb,newdb,local,options,password.olddb,需要进行压缩整理的数据库文件名,。
    newdb,进行压缩整理后新的数据库文件名。不能与olddb相同。
    local可选,
    options 可选,。
    password,可选,如果原数据库有加密码,就需要写入,否则无法完成。修复:
    DBEngine.RepairDatabase ("" & txtRepair.Text)
    数据库文件名, txtrepair.text.