你能帮帮我吗我想用C#压缩和修复我的accdb吗? [英] Could you help me I want to compact and repair my accdb using C#?

查看:78
本文介绍了你能帮帮我吗我想用C#压缩和修复我的accdb吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

兄弟们,我想压缩和修复我的accdb数据库..



我搜索并找到了这段代码,但我不知道如何使用它?



Please brothers I want to compress and repair my accdb database..

I search and found this code but I don't how to use it ?

public static void CompactAndRepair(string accessFile, Microsoft.Office.Interop.Access.Application app)
        {
           string tempFile = Path.Combine(Path.GetDirectoryName(accessFile),
                              Path.GetRandomFileName() + Path.GetExtension(accessFile));

            app.CompactRepair(accessFile, tempFile, false);
            app.Visible = false;

            FileInfo temp = new FileInfo(tempFile);
            temp.CopyTo(accessFile, true);
            temp.Delete();
        }

推荐答案

在您的应用程序中包含代码,并从Button Click事件处理程序中调用它。

在第一个参数中传递完整路径(例如:@D:\Temp \ Myy Databases \ MyDB.accdb),在第二个参数中传递Access实例:

Include the code in your application, and call it from a Button Click event handler.
Pass it the full path (for example: @"D:\Temp\My Databases\MyDB.accdb") in the first parameter, and an instance of Access in the second:
Microsoft.Office.Interop.Access.Application msAccess = new Microsoft.Office.Interop.Access.Application();





等等。可能很长一段时间......



Wait. Probably a long time...


有一个文章 [ ^ ]在CodeProject上可以提供帮助。

BTW您找到的示例代码需要更多的修正。它将您的访问数据库复制到临时文件,然后将其复制回原始文件。但也许你想检查数据库是否成功修复后再复制它甚至破坏原始副本...

你可能想要捕获任何异常来正确处理转换。

有关CompactRepair()方法的信息,请访问此处 [ ^ ]。
There is an article[^] on CodeProject that could help.
BTW the sample code you found need some more fixings. It copy your access database to a temporary file, then copy it back to the original file. But maybe you want to check if the database was successfully repaired before copying it back destroying even the original copy ...
And you may want to catch any exception to correctly handle the conversion.
Information about the CompactRepair() method can be found here[^].


这篇关于你能帮帮我吗我想用C#压缩和修复我的accdb吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆