添加引用 ->COM ->Microsoft Jet and Replication Objects 2.6 Library
命名空间 System.IO
public object CompactAccessDB(string FromDB, string ToDB)
{
try {
JRO.JetEngine jro;
jro = new JRO.JetEngine();
File.Delete(ToDB);
jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FromDB, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ToDB + ";Jet OLEDB:Engine Type=5");
File.Copy(ToDB, FromDB, true);
File.Delete(ToDB);
MsgBox(ToDB);
} catch (System.Exception CompactAccessDB_Err) {
throw CompactAccessDB_Err;
}
}
/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using xtp;
using System.Data;
//压缩数据库
string strS="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Application.StartupPath.Trim()+"//"+"EASIDOCLIENT.mdb";
//需要被压缩的文件
string strT="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Application.StartupPath.Trim()+"//"+"temp.mdb";
//压缩后生成的新文件
JRO.JetEngine jet=new JRO.JetEngineClass();
jet.CompactDatabase(strS,strT);
System.IO.File.Delete(Application.StartupPath.Trim()+"//"+"EASIDOCLIENT.mdb");
System.IO.File.Move(Application.StartupPath.Trim()+"//"+"temp.mdb",Application.StartupPath.Trim()+"//"+"EASIDOCLIENT.mdb");
.IO.File.Delete(Application.StartupPath.Trim()+"//"+"temp.mdb");