ASP code to view database records
First, ASP establishes a connection with the database.
<%
set dbconnection=Server.CREATEOBJECT(ADODB.CONNECTION)
DBPath = Server.MapPath(customer.mdb)
dbconnection.Open driver={Microsoft Access Driver (*.mdb)};dbq= & DBPath
Establish a connection with the database, the same as above.
SQL=select * from customer Order By time DESC
SET CustomerList=dbconnection.EXECUTE(SQL)
%>
Create a SQL query statement to query all records from the customer table. Order By time DESC means sorting in descending order of time, so that the last added information is displayed at the top. The following sentence executes the SQL query and returns the results to the Recordset object CustomerList.
<html>
<body>
<FONT SIZE=5><center>Database records</center></FONT>
<CENTER>
<TABLE BORDER=1>
<tr>
<td>Number</td>
<td>Company name</td>
<td>Contact person name</td>
<td>City</td>
<td>Phone number</td>
</tr>
<% DO WHILE NOT CustomerList.EOF %>
Check whether the last record has been reached. EOF means End of File.
<TR>
<TD><% =CustomerList(customer number) %></TD>
<TD><% =CustomerList(company name) %></TD>
<TD><% =CustomerList(Contact name) %></TD>
<TD><% =CustomerList(city) %></TD>
<TD><% =CustomerList(phone number) %></TD>
</TR>
<% =CustomerList(customer number) %> can be said to be the abbreviation of Response.Write method. Write the data in the customer number field to the TD tag space.
<%CustomerList.movenext
loop
%>
If the last item has not been reached, the pointer moves to the next item. Use Do While... Loop to obtain all records one by one.
</TABLE>
</CENTER>
<center>
<input type=button onclick=javascript:location.href='add.htm' value=Add data>
</center>
</BODY>
</HTML>