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


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

Example of creating connection to MS Acess Database in asp.net 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);
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();


Reference: http://howinaspnet.blogspot.com/2010/06/how-to-connect-to-ms-access-database-in.html


Related Articles

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

What is a GridView control in asp.net? 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 Asp.net? 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

Comments

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:
    Email: