Search Asp.Net Here

How to Connect to MS Access Database in Asp.net and C#.Net



Example of How to Connect to MS Access Database in Asp.net and C#.Net


In this example i m using the northwind database that install (optionally) with MS 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);
conn.Open();

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

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

// close the connection
conn.Close();
//Bind with grid view
GridView1.DataSource=ds;
GridView1.DataBind();



Comments :

2 comments to “How to Connect to MS Access Database in Asp.net and C#.Net”
Pranav Singh said...
on 

Hi this is really good article. thanks for sharing have a look of this also

http://www.dotnetpools.com/2013/10/how-to-bindfill-gridview-with-ms-access.html

Anonymous said...
on 

Nice Article
Here are also some articles with explanation and demo apps for connect c# with access and insert,delete operation with access database for beginners
http://geeksprogrammings.blogspot.com/2013/10/connect-access-database-with-c.html
http://geeksprogrammings.blogspot.com/2013/09/delete-record-from-access-database.html

Post a Comment