ASP‎ > ‎

Connect to an Access database and run a query

ASP code to connect to an Access database and run a select query.

<%
Dim adoCon         
Dim rs            
Dim strSQL         

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\inetpub\wwwroot\data.mdb"
Set rs = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM table;"

rs.Open strSQL, adoCon

'Loop through the recordset 
Do While not rs.EOF 

    'Write the HTML to display the current record in the recordset 
    Response.Write ("<br>") 
    Response.Write (rs("Name")) 
    Response.Write ("<br>") 
    Response.Write (rs("Comments")) 
    Response.Write ("<br>") 

    'Move to the next record in the recordset 
    rs.MoveNext 
Loop

rs.Close
Set rs = Nothing
Set adoCon = Nothing

%>
Comments