Create class for Access database connection
Hello to all,
Here we make on class that help to connect application's database by simply call class.
First we create Win form application.like Testapp. create one Access database like Testapp.accdb. after that we open application in visual studio and create one folder that name app_code. in this folder add one class file.and name them dbhelper.cs.
Include libraries
Now u can access dbhelper class.
Create object of class => DbHelper oDbHelper = new DbHelper();
Now db connection is open and you access database with this connection "OleDbConnection"
We can add some database operation functions like insert update delete and get data from database in this class.
Here we make on class that help to connect application's database by simply call class.
First we create Win form application.like Testapp. create one Access database like Testapp.accdb. after that we open application in visual studio and create one folder that name app_code. in this folder add one class file.and name them dbhelper.cs.
public class DbHelper
{
public static OleDbConnection dbConnection;
public DbHelper()
{
dbConnection = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0; Persist Security Info = False; Data Source=c:\\Testapp.accdb");
dbConnection.Open();
}
}
- For this code you need to include some libraries like System.Data.OleDb;
- Now time to use this class in application.
- First make this class build action as compile so you can access this core file.
Include libraries
using System.Data.OleDb;using Testapp.app_code;
Now u can access dbhelper class.
Create object of class => DbHelper oDbHelper = new DbHelper();
Now db connection is open and you access database with this connection "OleDbConnection"
We can add some database operation functions like insert update delete and get data from database in this class.
Comments
Post a Comment