Search DaTutorials:  
HOME
ADO Tutorials
Introduction
Tutorials
Reference

Sort records ascending

Description:


How to sort and display the records from a table on a fieldname ascending.

Code:


<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT FirstName, LastName, Occupation FROM Employees ORDER BY FirstName"
rs.Open sql, conn
%>
<table border="1" width="100%">
<tr>
<%
for each x in rs.Fields
    response.write("<th align='center' bgcolor='#9ABEF4'>"& x.name & "</th>")
next
%>
</tr>
<%
do until rs.EOF
%>
<tr>
    <%for each x in rs.Fields%>
    <td><%Response.Write(x.value)%></td>
    <%
    next
    rs.MoveNext
    %>
</tr>
<%
loop
rs.close
conn.close
%>
</table>

</body>
</html>

Working example:


Keywords:

ADO: Connection Provider Property, Connection Open method, Recordset Fields Collection, Recordset Object

ASP: Server, Response.Write

VBscript: For Each...Next Statement, Do...Loop Statement


Home     Link To Us     Ad With Us     Contact Us     Tell A Friend     Affiliates     Blog     MsOfficeHelp