Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Thanked 0 Times in 0 Posts

    New to ADO, having some problems.

    Hi, i'm currently doing my final year project for university and I need to display a database on an html page, i decided to do it using ADODB. I've never used this before and i'm currently having some problems that i'm hoping someone will be able to help me with.

    Here is the code in my .asp file:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
    <html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="content-type" 
    		content="text/html;charset=utf-8" />
    <link rel="stylesheet" href="rostercss.css" type="text/css" media="screen" />
    <div id="roster"> <!--roster div-->
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Open "c:/inetpub/wwwroot/Roster.accdb"
    set rs = Server.CreateObject("ADODB.recordset")
    rs.Open "SELECT Number, FirstName, LastName FROM Roster", conn
    <table border="1" width="100%">
      <%for each x in rs.Fields
        response.write("<th>" & x.name & "</th>")
      <%do until rs.EOF%>
        <%for each x in rs.Fields%>
    </div> <!--end roster div-->
    And here is a picture of what outputs when i run the asp file in firefox:

    I have the .asp file on a uni drive which i'm accessing via VPN, and the database file is in C:\webdata\wwwroot. I have IIS turned on.

    Please help i'ev been stuck on this for ages!

    Thanks in advance!

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Thanked 20 Times in 20 Posts
    Hey aoami,

    Few comments...

    1. You are working with Legacy ASP and you posted in ASP.NET section. It doesn't matter to me, but you might get better responses if you post in the correct section.

    2. The picture you posted is not visible.

    3. Putting HTML tags inside Response.Write is a bad style. Don't do that. For example, you have
    <%for each x in rs.Fields
      response.write("<th>" & x.name & "</th>")
    Instead, do something like this (hope I got that right, I haven't used classic ASP in a while, but whatever you get the idea)...

    <%for each x in rs.Fields%>
    3. Debugging your server-side code first before you start implementing the output will help you figure out what's going on. So, I would comment everything out first. Start with the connection setup (I mean up to line conn.Open). Run that. If you get an error, then the problem is in your connection. If connection is good, uncomment the recordset code. If recordset is okay, now do some simple Response.Write for each record, etc...
    The point is, don't rush with the HTML stuff.



    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts