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]  Databases
     [next Lesson]  List Box Displayed Generically

Database -- Simple Table Display by Charles Carroll

This page demonstrates the capabilities how to display a table from a SQL statement.

   filename=/learn/test/dbsimple.asp

<Test Script Below>


<html><head>
<TITLE>dbsimple.asp</TITLE>
</head>
<body bgcolor="#FFFFFF">
<% 
' this code opens the database
myDSN="DSN=Student;uid=student;pwd=magic"
set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN

' this code retrieves the data
mySQL="select * from publishers where state='NY'"
set rstemp=conntemp.execute(mySQL)

' this code detects if data is empty
If rstemp.eof then
    response.write "No records matched<br>"
    response.write mySQL & "<br>So cannot make table..."
    connection.close
    set connection=nothing
    response.end
end if
%>
<table border=1>
<%
' This code puts fieldnames into column headings
response.write "<tr>"
for each whatever in rstemp.fields
    response.write "<td><B>" & whatever.name & "</B></TD>"
next
response.write "</tr>"

' Now lets grab all the records
DO UNTIL rstemp.eof
    ' put fields into variables
    pub_id=rstemp("pub_id")
    pub_name=rstemp("pub_name")
    city=rstemp("city")
    state=rstemp("state")
    country=rstemp("country")

    ' write the fields to browser
    cellstart="<td align=""top"">"
    response.write "<tr>"
    response.write  cellstart & pub_id & "</td>"
    response.write  cellstart & pub_name & "</td>"
    response.write  cellstart & city & "</td>"
    response.write  cellstart & state & "</td>"
    response.write  cellstart & country & "</td>"

    response.write "</tr>"
    rstemp.movenext
LOOP
%>
</table>

<%
' Now close and dispose of resources
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
</body></html>

There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.