找传奇、传世资源到传世资源站!

C# access数据库修复工具源码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboardusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using ADOX;using JRO;using System.IO; //首先引用C:\Program Files\Common Files\System\ado\msadox.dll,该DLL包含ADOX命名空间;//接着引用C:\Program Files\Common Files\System\ado\msjro.dll,该DLL包含JRO命名空间namespace Ex16_04{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } //打开选择数库咱径 private void button1_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Access数据库|*.mdb"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; strPathMdb = textBox1.Text.TrimEnd(); } } //开始压缩数据库库 string strPathMdb = null; private void button2_Click(object sender, EventArgs e) { if (!File.Exists(strPathMdb)) //检查数据库是否已存在 { MessageBox.Show("目标数据库不存在,无法压缩","操作提示"); return; } //声明临时数据库的名称 string temp = DateTime.Now.Year.ToString(); temp = DateTime.Now.Month.ToString(); temp = DateTime.Now.Day.ToString(); temp = DateTime.Now.Hour.ToString(); temp = DateTime.Now.Minute.ToString(); temp = DateTime.Now.Second.ToString() ".bak"; temp = strPathMdb.Substring(0, strPathMdb.LastIndexOf("\\") 1) temp; //定义临时数据库的连接字符串 string temp2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" temp; //定义目标数据库的连接字符串 string strPathMdb2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" strPathMdb; //创建一个JetEngineClass对象的实例 JRO.JetEngineClass jt = new JRO.JetEngineClass(); //使用JetEngineClass对象的CompactDatabase方法压缩修复数据库 jt.CompactDatabase(strPathMdb2, temp2); //拷贝临时数据库到目标数据库(覆盖) File.Copy(temp, strPathMdb, true); //最后删除临时数据库 File.Delete(temp); MessageBox.Show("修复完成"); } //////////////////// private void Form1_Load(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { Application.Exit(); } /////////////////////// }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复