View Full Version : New to ADO, having some problems.

03-09-2011, 05:21 PM
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:


<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!

03-10-2011, 08:44 PM
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.