Connect to MS Access DB on the server

Discussion in 'Databases' started by pdfpublisher, May 3, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I'm trying to connect to my MS Access database from an .aspx page and would sincerely appreciate help with checking this code obtained from the Discount ASP.Net knowledge base article titled "Query an Access database with ASP using a DSN-less conection". My database path is: http://www. mysite.com/_database/Nwind.mdb. My question: Is this code correct? Where should I place the code between the declaration <% %>? Should the <table border="1"> tag be placed between the content placeholders?
    <%
    Dim cnnSimple ' ADO connection
    Dim rstSimple ' ADO recordset
    Set cnnSimple = Server.CreateObject("ADODB.Connection")
    ' DSNLess
    cnnSimple.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp; Server.MapPath("_database\Nwind.mdb"))
    Set rstSimple = cnnSimple.Execute("SELECT * FROM Customers")
    %>
    <P> Connecting to Access with Ole 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
    %>
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    I think your path is wrong


    should be Server.MapPath("\_database\Nwind.mdb")


    The table tag should NOT be within the loop, you want to create 1 table w/ each row of data returned from the query displayed as a single row.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Thanks Bruce,


    I'll make the changes and follow your advice.
     
  4. When you say:


    The table tag should NOT be within the loop, you want to create 1 table w/ each row of data returned from the query displayed as a single row.


    Could you give me an example.


    Thanks.
     
  5. I think Bruce was talking about your HTML table in the loop, but it does look correct so maybe he was in a hurry. [​IMG]
    The loop you have there will create a row with two records side by side until the last DB table row is reached.
    Salute,
    Mark
     
  6. Thanks Mark,


    I sincerely appreciate your quick response.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page