Connecting to a Microsoft Access database with ASP.NET - Connecting to a Microsoft Access database directly using ASP.NET
(Page 2 of 6 )
Try to create your own web application using Visual Studio.NET (I named mine “ConnectAccessDirect” for this demonstration). Design your web form to look something like the following (Fig1).

After designing the form, switch to the code and add the following line at the top.
Imports System.Data.OleDb
I am importing the namespace “System.Data.Oledb” because I would like to connect to the Access database using the OLEDB provider for .NET. Add the following code to your “show/refresh” button:
Private Sub btnList_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnList.Click
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\AccessDB\MyDB.mdb;User Id=admin;Password=;")
Dim da As New OleDbDataAdapter("select * from emp", cn)
Dim dt As New DataTable
da.Fill(dt)
da.Dispose()
cn.Dispose()
Me.DataGrid1.DataSource = dt
Me.DataGrid1.DataBind()
End Sub
Once you complete the above, you execute your application (by pressing F5) and click on the button “Show/Refresh.” You should be able to see all the rows on the screen. Till now, you have not needed to configure anything. Now, let us proceed to the next section.
Next: Manipulating a Microsoft Access database directly using ASP.NET >>
More Microsoft Access Articles
More By Jagadish Chaterjee