public class dbConnection
{
public dbConnection()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string connection
{
get
{return"Data Source=xxxxxxmdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;";}
}
}
在主界面mainform.cs添加
private static OleDbConnection oleConnection1 = null;
public static OleDbConnection getConnection()
{
if(oleConnection1==null)
{
oleConnection1 = new OleDbConnection(dbConnection.connection);
oleConnection1.Open();
}
return oleConnection1;
}
调用方法:
if(oleConnection1==null)
oleConnection1 = MainForm.getConnection();