基本信息
源码名称:C# access数据库修复工具源码
源码大小:0.12M
文件格式:.zip
开发语言:C#
更新时间:2018-02-17
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using 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();
}
///////////////////////
}
}