Active Server Page logo View ASP Source


<%option explicit%>
<html>
<head><title>List Database</title></head>
<body>
<%
dim conn,rs,x
set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.mappath("database.mdb"))
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT * FROM tblGuestBook",conn
%>

<h2>List Database (click on button to edit)</h2>
<table border="1" width="100%">
<tr>
<%
for each x in rs.Fields
      response.write("<th>" & ucase(x.name) & "</th>")
next
%>

</tr>
<%do until rs.EOF%>
<tr>
<form method="post" action="demo_db_edit.asp">
<%for each x in rs.Fields
      if x.name="no" then%>

           <td><input type="submit" name="no" value="<%=x.value%>"></td>
      <%else%>
           <td><%Response.Write(x.value)%></td>
      <%end if
next
%>

</form>
<%rs.MoveNext%>
</tr>
<%
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
%>

</table>

<p>
<a href="showcode.asp?source=demo_db_list.asp">View source code on how to list a database table in an HTML table</a>
</p>

<p>
<b>Note:</b> If you click on the numbers in the "no" column you will be taken to a new page. On that page you will be able to look at the source code on how to create input fields based on the fields from one record in the database table.
</p>

<p>
<a href="ado_demo.asp">Return to previous page</a>
</p>

</body>
</html>