Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Errors: Resources Online
     [next Lesson]  Debug variables Easy Way

Displaying A Table from Query w/Bells & Whistles

Displaying a table take very little code. A veteran will expand the basic code to deal with many errors that a novice will not have encountered until testing their web on a large scale.

   filename=/learn/test/dbtablewitherrortrap.asp

<Test Script Below>


<TITLE>dbtablewitherrortrap.asp</TITLE>
<body bgcolor="#FFFFFF">
<!--#include file="lib_errors.asp"-->
<% 
on error resume next
attempt="create connection object"
set conntemp=server.createobject("adodb.connection")
Call ErrorVBScriptReport(attempt)

attempt="opening DSN"
conntemp.open "DSN=Student;uid=student;pwd=magic"
Call ErrorVBScriptReport(attempt)
Call ErrorADOReport(attempt,conntemp)

attempt="select * from authors where AU_ID<16"
set rstemp=conntemp.execute(attempt)
Call ErrorVBScriptReport(attempt)
Call ErrorADOReport(attempt,conntemp)
If rstemp.eof then
    response.write "No records matched your query" & "<P>"
    response.write attempt
    response.end
end if

attempt="counting fields"
howmanyfields=rstemp.fields.count -1
Call ErrorVBScriptReport(attempt)
Call ErrorADOReport(attempt,conntemp)
%>
<table border=1>
<tr>
<% 'Put Headings On The Table of Field Names
for i=0 to howmanyfields %>
    <td><b><%=rstemp(i).name %></B></TD>
<% next %>
</tr>

<% ' Now lets grab all the records
do while not rstemp.eof %>
    <tr>
    <% for i = 0 to howmanyfields%>
            <td valign=top><%=rstemp.fields(i)%></td>
    <% next %>
    </tr>
    <%
    rstemp.movenext
loop
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
</table>
</BODY>
</HTML>

The error trapping library looks like this:

   filename=/learn/test/lib_errors.asp

<Test Script Below>


<%
SUB ErrorVBScriptReport(parm_msg)
    If  err.number=0 then
        exit sub
    end if
    pad="&nbsp;&nbsp;&nbsp;&nbsp;"
    response.write "<b>VBScript Errors Occured!<br>"
    response.write parm_msg & "</b><br>"
    response.write pad & "Error Number= #<b>" & err.number & "</b><br>"
    response.write pad & "Error Desc.= <b>" & err.description & "</b><br>"
    response.write pad & "Help Context= <b>" & err.HelpContext & "</b><br>"
    response.write pad & "Help File Path=<b>" & err.helpfile & "</b><br>"
    response.write pad & "Error Source= <b>" & err.source & "</b><br><hr>"
END SUB

SUB ErrorADOReport(parm_msg,parm_conn)
    HowManyErrs=parm_conn.errors.count
    IF  HowManyErrs=0 then
        exit sub
    END IF
    pad="&nbsp;&nbsp;&nbsp;&nbsp;"
    response.write "<b>ADO Reports these Database Error(s) executing:<br>"
        response.write SQLstmt & "</b><br>"
    for counter= 0 to HowManyErrs-1
        errornum=parm_conn.errors(counter).number
        errordesc=parm_conn.errors(counter).description
        response.write pad & "Error#=<b>" & errornum & "</b><br>"
        response.write pad & "Error description=<b>"
        response.write errordesc & "</b><p>"
    next
END SUB
%>

Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site