【 tulaoshi.com - 编程语言 】
#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");
}