Here is an easy way to get access for example, to an Access database located in your program folder using
//Add this namespace for database handle
using System.Data.OleDb;
public OleDbConnection GetConnection()
{
OleDbConnection acc = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb";
return acc;
}
Later, when you want to open the database to load, save or whatever you need to do you can use the sentence, being Instance() a method used by Singleton pattern and ConnectionMgr the class name for managing connections:
IDbConnection acc = ConnectionMgr.Instance().GetConnection();
No comments:
Post a Comment