Forum Moderators: open

Message Too Old, No Replies

view contents of database

not working and cannot find errors

         

Blelisa

3:00 pm on Aug 12, 2005 (gmt 0)

10+ Year Member



Hello all.
I am trying to have a web page list the contents of my database table. I have been trying for ever and cannot find what I am doing wrong.
Here is my code: (I hope it is not a mess I am new too this)I have included comments to walk myself through this.
<%@language="VBScript"%>
<%Option Explicit%>
<html>
<head>
<title>Complete Bug Database</title>
</head>
<body>
<%
'creating adodb.connection to connect to database, and setting connection to open
Dim connection
set connection=Server.CreateObject("ADODB.Connection")
connection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
server.MapPath("data/Developers.mdb")
connection.Open

'Creating objrs as recordset to use to communicate with my database by putting my string that holds my sql statement in it
Dim ObjRS
Set objRS = Server.CreateObject("ADODB.Recordset")

'Create string to hold my sql command
Dim strSQL
strSQL = "SELECT * FROM tblbug"

'open recordset and communicate with database that I want to perform sql inside my string and to do it in my database in my connection
ObjRS.Open strSQL, connection

'Print out the results, stop trying when there is null entered and keep moving to next record
Do Until objRS.EOF = True
<table>
<tr>
<td>Response.Write "Ticket Number =" & objRS("ticketID")</td>
<td>Response.Write "Date =" & objRS("date")</td>
<td>Response.Write "Description =" & objRS("description")</td>
</tr>
</table>
objRS.MoveNext
Loop

'Close and empty my record set and my connection
objRS.Close
Set objRs=Nothing
connection.Close
Set connection=Nothing
%>
</body>
</html>

Thanks in advance for your help!

mattglet

4:43 pm on Aug 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:

Do Until objRS.EOF = True
%>
<table>
<tr>
<td>Ticket Number =<%=objRS("ticketID")%></td>
<td>Date =<%=objRS("date")%></td>
<td>Description =<%=objRS("description"%></td>
</tr>
</table>
<%
objRS.MoveNext
Loop

You needed to separate your HTML from your ASP.

aspdaddy

5:40 pm on Aug 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also if you can, always do this:
Dim ObjRS
set ObjRS=connection.Execute strSQL

instead of this:
Dim ObjRS
Set objRS = Server.CreateObject("ADODB.Recordset")
ObjRS.Open strSQL, connection

aspdaddy

6:30 pm on Aug 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



FYI, If you get a lot of requests, using <%= and & (string concat) will slow things down quite a bit. I have been re-writing some old sites with this method and the difference in speed is phenomenal, try it and see you will be surprised.

While Not(objRS.EOF)
With Response
.write "<table><tr><td>Ticket Number ="
.write objRS("ticketID")
.write "</td><td>Date ="
.write objRS("date")
.write "</td><td>Description ="
.write objRS("description")
.write "</td></tr></table>"
End With
objRS.MoveNext
Wend

mrMister

1:32 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's also a nice freeware String Concatenation object available for cases where While isn't appropriate:

[ranainside.com...]