How query an Access database with a DSN/ODBC source

<
Dim cnnSimple  ' ADO connection 
Dim rstSimple  ' ADO recordset 
Set cnnSimple = Server.CreateObject("ADODB.Connection") 
' DSNLess 
cnnSimple.Open = "DSN=[DSN Source Name]" 
Set rstSimple = cnnSimple.Execute("SELECT * FROM Table1") 
%> 
<P> Connecting to Access DB with ODBC connection </P> 
<table border="1"
<
Do While Not rstSimple.EOF 
            %> 
            <tr> 
                        <td><%= rstSimple.Fields(0).Value %></td
                        <td><%= rstSimple.Fields(1).Value %></td
            </tr> 
            <
            rstSimple.MoveNext 
Loop 
%> 
</table> 
<
rstSimple.Close 
Set rstSimple = Nothing 
cnnSimple.Close 
Set cnnSimple = Nothing 
%> 


If you run into problems when using this code, please post in our community forum. Technical support is unable to assist with specific coding issues.

Article ID: 761, Created On: 1/28/2010, Modified: 4/13/2010