...

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



aoami
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:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">


<head>

<meta http-equiv="content-type"
content="text/html;charset=utf-8" />

<link rel="stylesheet" href="rostercss.css" type="text/css" media="screen" />

<title>Roster</title>

</head>
<body>

<div id="roster"> <!--roster div-->

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.ACE.OLEDB.12.0"
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%">
<tr>
<%for each x in rs.Fields
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>
</table>

</div> <!--end roster div-->
</body>
</html>

And here is a picture of what outputs when i run the asp file in firefox:

http://img109.imageshack.us/img109/3811/adoo.png

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!

Mike_O
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>")
next%>

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%>
<th>
<%=x.name%>
</th>
<%next%>

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.

Regards,
Mike



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum