MS Access Compact Database từ mã lệnh C#

Sử dụng JRO

  • Add COM reference: Microsoft Jet and Replication Objects 2.6 Library
  • using JRO

Add COM reference: Microsoft Jet and Replication Objects 2.6 Library

JRO Ms Access Database Compact

Thêm Microsoft Jet and Replication Objects 2.6 Library

Đoạn mã C#: using JRO... file trung gian tên sample_compact.mdb

using JRO;

...

JRO.JetEngine jet = new JRO.JetEngine();

string sourceDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=sample.mdb; Jet OLEDB:Database password='1234'";

string destinationDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=sample_compact.mdb; Jet OLEDB:Database password='1234'";

jet.CompactDatabase(sourceDB, destinationDB);

if (System.IO.File.Exists("sample.mdb"))

{

System.IO.File.Delete("sample.mdb");

System.IO.File.Copy("sample_compact.mdb", "supplychain.mdb");

}

Copy »


Keywords: Compact Database; CompactDatabase; CompactDatabase in C#.

TOP