Latest web development tutorials

ADO Sort

We can use SQL to define how to sort the record set data.


Sorting data

We want to show the "Customers" table "Companyname" and "Contactname" field, and according to "Companyname" sort (remember to save with the suffix .asp):

Examples

<html>
<body>

<%
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 ORDER BY CompanyName"
rs.Open sql, conn
%>

<table border="1" width="100%">
<tr>
<%for each x in rs.Fields
response.write("<th>" & 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>

Examples show »


Examples

More examples

The records in descending order according to the name of the specified field
How to sort the data according to the specified field name

Allows users to select which columns are sorted according to
Allows users to select which columns are sorted according to