vb.net(2008)压缩修复Access(2000-2003)代码如下,Access在存储图片方面有点点问题,一张小图片也会占用很大的容量,这可能也存储方式有关,目前calf用的是rtf直接存取,不过这不是本文的重点。Access在删除了里面的数据后,容量并不会自动释放,Access软件本身自带有压缩修复功能,那怎么能在vb.net中用代码实现呢?下面这个过程可以参考下:
折叠ASP/Visual Basic Code复制内容到剪贴板
- Public Sub RepairAccess()
- 'Call msgInfo("正在修复压缩...", "")
- Dim objJRO As Object = Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"))
- objJRO.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\data2003.mdb", "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\data2004.mdb")
- Kill(Application.StartupPath & "\data2003.mdb")
- objJRO.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\data2004.mdb", "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\data2003.mdb")
- Kill(Application.StartupPath & "\data2004.mdb")
- Call msgInfo("压缩成功!目前:", dataVolume)
- 'objJRO.CompactDatabase(ConnStr, ConnStr)
- 'Kill(Application.StartupPath & "\data2003.bak")
- 'objJRO.CompactDatabase("Data Source=.\DATA\BZJsjk.DLL;Jet OLEDB:Database Password=(.LSY810404zhxy.)", "Data Source=.\DATA\BZJsjk.bak;Jet OLEDB:Database Password=514892")
- 'Kill(Application.StartupPath & "\DATA\BZJsjk.dll")
- 'objJRO.CompactDatabase("Data Source=.\DATA\BZJsjk.bak;Jet OLEDB:Database Password=(.LSY810404zhxy.)", "Data Source=.\DATA\BZJsjk.DLL;Jet OLEDB:Database Password=514892")
- 'Kill(Application.StartupPath & "\DATA\BZJsjk.bak")
- End Sub