Brinkster Knowledge Base

KB Home   /  Support  /  Database  /  MS Access  /   How do I connect to a MS Access database with ASP.NET 1.1
How do I connect to a MS Access database with ASP.NET 1.1 Articles
** Important information regarding the following code samples. **

Be sure to make note of the following when using these coding examples:
1. Replace username with your Brinkster hosting account username.
2. Replace password with the password for the account used above.
3. Replace C:\sites\single??\username\database\YourDB.mdb with your own absolute root path. Your specific path is listed in Website Settings of the account Control Panel.


<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.OleDB" %>

<%@ Page language="VB" %>

 

<%

        Dim sPath As String = "C:\sites\Single??\Username\database\YourDB.mdb"

        Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0; DATA Source=" & sPath & ";"

        Dim objConn As OleDbConnection

        Dim cmdSelect As OleDbCommand

        Dim dtrReader As OleDbDataReader

        Dim strResults As String

 

        objConn = New OleDbConnection( connString )

 

        objConn.Open()

        cmdSelect= New OleDbCommand( "SELECT SomeField From SomeTable", objConn)

        dtrReader= cmdSelect.ExecuteReader()

        While dtrReader.Read()

               Response.Write(dtrReader("SomeField") & "<br>")

        End While

 

        dtrReader.Close()

        objConn.Close()

 

%>