01 Access数据库 测试连接

时间:2022-03-14 04:58:34

附件:http://files.cnblogs.com/xe2011/AccesssConnectionState.rar

01 Access数据库 测试连接

using System.Data.OleDb;
using System.Data.Common;

//连接
private void button1_Click(object sender, EventArgs e)
{
    string FileName = "MangerDataBase.mdb";
    string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" +FileName;
    OleDbConnection con = new OleDbConnection(ConStr);
    con.Open();

    if (con.State == ConnectionState.Open)
    {
        MessageBox.Show("Access数据库的连接成功!");
    }
    else
    {
        MessageBox.Show("Access数据库的连接失败!");
    }
    con.Close();
}