ASP can be used to display information directly from a database residing on the server, without the database naming conventions being available to the viewer. It also allows ease and speed in accessing the database information.
Note that the database information and other information
pertaining to the table shown is not shown in the final html code
available in a browser. The ASP code below connects to a MySQL
database, and produces a simple table output from the database.
<% ' this code opens the database connect_string =
"Driver={Mysql}; Server=
localhost; Database=domainname_com; UID=username;
PWD= password"set dbConn=
server.createObject("ADODB.connection")
dbConn.open connect_string
' this code retrieves the data
mySQL="select * from asptest"
set rstemp=dbConn.execute(mySQL)
' this code detects if data is empty
If rstemp.eof then
response.write "No records matched
"
response.write mySQL & "
So cannot make table..."
connection.close
set connection=
nothing
response.end end
if
%>
<% ' This code puts fieldnames into column
headings response.write"<tr>"
for each whatever in rstemp.fields
response.write "<td>" & whatever.name & "</TD>"
next response.write "</tr>" ' Now lets grab all the records DO
UNTIL rstemp.eof ' put fields into variables Name=rstemp("name")
City=rstemp("city") State=rstemp("state") Email=rstemp("email")
Phone=rstemp("phone") Name=rstemp("name")' write the fields to
browser cellstart=
"<td align=
""top"">" response.write
"<tr>" response.write cellstart
& Name & "</td>" response.write
cellstart&
City&
"</td>"response.write
cellstart&
State&
"</td>"response.write cellstart & Email & "</td>"
response.writecellstart &Phone&
"</td>" response.write"</tr>"
rstemp.movenext LOOP %> <% ' Nowclose
and dispose of resourcesrstemp.close set rstemp=
nothing dbConn.close set dbConn=
nothing %> From here youcan
easily modify the SELECT statement tolook
for specificresults,
much
as
you
would
from a Search box. So this modified
SELECT statement:
mySQL="select * from asptest where phone LIKE '555%'"
produces a subsection of the results from the first code example.