ADO Display
ADO Display
The most common way to display data from a recordset is to display it in an HTML table.
Display field names and field values
We have a database called "Northwind" and we want to display the data from the "Customers" table (remember to save this file with a .asp extension):
Instance
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT * FROM Customers", conn
do until rs.EOF
for each x in rs.Fields
Response.Write(x.name)
Response.Write(" = ")
Response.Write(x.value & "
")
next
Response.Write("
")
rs.MoveNext
loop
rs.close
conn.close
%>
Instance Demo »
Display field names and field values in an HTML table
We can also display the data from the "Customers" table in an HTML table using the following code:
Instance
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT Companyname, Contactname FROM Customers", conn
%>
<%do until rs.EOF%>
<%for each x in rs.Fields%>
<%next
rs.MoveNext%>
<%loop
rs.close
conn.close
%>
| <%Response.Write(x.value)%> |
Instance Demo »
Add a header to an HTML table
Add a header to an HTML table to improve readability. (Keep the file extension as .html):
Example
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers"
rs.Open sql, conn
%>
<%for each x in rs.Fields
response.write("
next%>
<%do until rs.EOF%>
<%for each x in rs.Fields%>
<%next
rs.MoveNext%>
<%loop
rs.close
conn.close
%>
| " & x.name & " | ")
|---|
| <%Response.Write(x.value)%> |
Instance Examples »
More Examples
Adding Color to an HTML Table
How to add color to an HTML table to make it more aesthetically pleasing.