using System.Data.OleDb;
//数据库连接字符串
String strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=.\WuBiDb.accdb;
Jet OLEDB:Database Password=123456";//Persist Security Info=False
//连接数据库方法
public void ConnDb(String strConn)
{
using (dbConn= new OleDbConnection(strConn))
{
try
{
dbConn.Open();
MessageBox.Show("连接数据库Success!" );
}
catch (Exception ex)
{
MessageBox.Show("连接数据库失败:"+ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
}