1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void cmdCompact_Click(object sender, System.EventArgs e)
{
// Faire une référence COM à MSJRO.DLL
String PROVIDER = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
String JETOLEDB = ";Jet OLEDB:Engine Type=5";
String strDBTarget = "C:\\Documents and Settings\\Argyronet\\Mes documents\\MyDB.mdb";
String strDBTemp = "C:\\Documents and Settings\\Argyronet\\Mes documents\\MyTMP.mdb";
// Création de la Base...
CreateDB();
try
{
JRO.JetEngine oJRO = new JRO.JetEngine();
oJRO.CompactDatabase(PROVIDER + strDBTarget, PROVIDER + strDBTemp + JETOLEDB);
System.IO.File.Delete(strDBTarget);
System.IO.File.Move(strDBTemp, strDBTarget);
}
catch (Exception ex)
{
Console.WriteLine("{0} Boulette !!!", ex);
}
}
private void cmdCreate_Click(object sender, System.EventArgs e)
{
CreateDB();
}
private void CreateDB()
{
// Faire une référence COM à Microsoft ADO Ext. 2.7 for DDL and Security
String PROVIDER = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
String JETOLEDB = ";Jet OLEDB:Engine Type=5";
String strDBTarget = "C:\\Documents and Settings\\Argyronet\\Mes documents\\MyDB.mdb";
ADOX.CatalogClass clsCAT = new ADOX.CatalogClass();
clsCAT.Create(PROVIDER + strDBTarget + JETOLEDB);
ADODB.Connection oCnx = clsCAT.ActiveConnection as ADODB.Connection;
if (oCnx != null)
{
oCnx.Close();
}
clsCAT.ActiveConnection = null;
clsCAT = null;
} |
Partager