How to connect to MS Access Database in and C#.Net

How to connect to MS Access Database in and C#.Net

Example of creating connection to MS Acess Database in and C#

In this example i m using the northwind database that install (optionally) with access database

First Drag a Grid view and Link Button control in your desing page

Use the following Namespaces in your .cs file

using System.Data;
using System,Data.oledb;

now write the following code in your Link Button click event

string conString =@"Provider=Microsoft.JET.OLEDB.4.0;"
+ @"data source=c:\data\Northwind.mdb";

// create an open the connection
OleDbConnection conn = new OleDbConnection(conString);

// create the DataSet
DataSet ds = new DataSet();

// create the adapter and fill the DataSet
OleDbDataAdapter adapter=new OleDbDataAdapter("Select * from Customers", conn);

// close the connection
//Bind with grid view


Related Articles

What is GridView control and how to bind GridView to data?

What is a GridView control in Want to learn how to connect GridView to a database? This article will teach you more about the databound control GridView, properties and events of GridView and binding a GridView control to data.

How to add Buttons in Data GridView?

Want to add buttons to the GridView control in Need to execute a set of statements when the user clicks on the button in the GridView? Learn how to add controls like button to the GridView control and write C# code for user activities performed like Clicking of Buttons in the GridView.

More articles: ADO database connection MS access database Gridview


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: