Brinkster Knowledge Base

KB Home   /  Support  /  Database  /  MS Access  /   How do I connect to a MS Access database with ASP.NET 2.0
How do I connect to a MS Access database with ASP.NET 2.0 Articles
IMPORTANT: Be sure to make note of the following when using these coding examples:
1. Replace username with your Brinkster hosting account username.
2. Replace C:\sites\single??\username\database\YourDB.mdb with the path to your web space.
3. Replace password with the password for the email account used above.
4. Please log into your account, select the web site settings, and use the absolute path to your file structure.

<%

 

Dim sPath as String = "C:\sites\single??\username\database\YourDB.mdb"

Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & sPath & ""

Dim sSQL As String = "Select * from tablename"

Dim objConnection As Data.OleDb.OleDbConnection = New Data.OleDb.OleDbConnection(strConnection)

Dim objCommandAuction1 As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand(sSQL, objConnection)

Dim oDr As Data.IDataReader

 

Try

    objConnection.Open()

    oDr = objCommandAuction1.ExecuteReader()

    Do While oDr.Read

        'Write information from database here

    Loop

    oDr.Close()

Catch ex As Exception

    Response.Write(ex.Message)

End Try

 

objConnection.Close()

 

%>