Step 1
Create a mdb file in MS Access as follows:
- Open MS Access
- Choose Blank Database
- Save it as Microsoft Office Access Database (2000) format
Hence your mdb file is created.
Step 2
Create a table in your database.
Step 3
Create a Windows form with a button for connectivity.
Step 4
Import system.Data.OleDb
Now on button click event connect with MS Access:
- using System.Data.OleDb;
-
- namespace WindowsFormsApplication3
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- OleDbConnection conn;
- private void btnConnect_Click(object sender, EventArgs e)
- {
-
- var DBPath = Application.StartupPath + "\\Connection.mdb";
- conn = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + DBPath);
- conn.Open();
- System.Windows.Forms.MessageBox.Show("Connected successfully");
-
- }
- }
- }
Hence your connection is established,