Search Forum
(57415 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


              
Printable Version

Connecting to MS Access DataBase From an ASP.NET Web Form
By Shanker


The following steps will help you to conenct to a MS Access Database
 from your ASP.NET web form.

Step 1 :
Create an Asp.Net Web Application 
a)File->New->Project
  select ASP.NET Web Application
    Click Ok
Step 2:
In the Design View of the form , from the WebForms ToolBox

Drag and Drop a Button
Drag and Drop a DataGrid

Step 3
From the Data ToolBox,
Drag and Drop a OleDBDataAdapter

Now the Data Adapter Configuration Wizard Will Appear

Click ON Next
Click On New Connection
In the Data Link Properties Form , Click On Provider

Choose Microsoft Jet 4.0 OLE DB Provider(Or 3.51 OLE DB Provider, depending on MSAccess installed on your machine)
Click On Next


In the resulting window, Enter the complete path to your Local 
Access DataBase (For ex:C:\SampleDB\BooksDb.mdb). 
You can also browse the .mdb file using the Button next to the Text Box.

Click on Test Connection to make sure that the DB exists and that you are able to connect 
to the Database.
Dont forget to enter the password information if you are using a password for your database.
Click on Ok.

Step 4
Click on Next in the Data Adapter Configuration Wizard
Make sure the "Use Sql Statements" Radio Button is Checked and Click Next
Enter the SQL query in the Resulting window (For ex: Select * from Books)

(Or You can use the Query Builder to build your queries)
Click Next
Click Finish 


Now you are all set to retreive the data from the DataBase you specified.

Step 5
Now In the Button Click Event, include the following Statements


DataSet dataset=new DataSet();
this.oleDbDataAdapter1.Fill(dataset);
this.DataGrid1.DataSource=dataset;
DataGrid1.DataBind();

Compile and run your program. If you click the Button, you can see the Datagrid is being 
populated by the data from the DataBase.