用ADO压缩Access2000库
#include "utilcls.h"
void CompactDatabase(String f1,String psw1, String f2,String psw2)
{
String Provider1="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ f1 + ";Jet OLEDB:Database Password=" + psw1;
String Provider2="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ f2 + ";Jet OLEDB:Database Password=" + psw2;
Variant Adoobj=Variant::CreateObject("JRO.JetEngine");
Adoobj.OleProcedure("CompactDatabase",Provider1,Provider2);
AdoObj.Clear( ); // 释放 ADO工具
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String f1="yhecdagl1.mdb"; // 源库1
String psw1="yhecdagl"; // 暗码1
String f2="yhecdagl2.mdb"; // 新目标库2
String psw2="yhecdagl2"; // 新暗码2
String dir=ExtractFilePath(Application->ExeName);
if (FileExists(f2))
DeleteFile(f2);
CompactDatabase(dir+f1,psw1,dir+f2,psw2);
ShowMessage("Finished");
}