Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
03-09-2011, 04:21 PM #1
- 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" "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>
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, 07:44 PM #2
- Join Date
- Apr 2009
- Thanked 20 Times in 20 Posts
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
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)...Code:<%for each x in rs.Fields response.write("<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...Code:<%for each x in rs.Fields%> <th> <%=x.name%> </th> <%next%>
The point is, don't rush with the HTML stuff.