ADO Sort Data

ADO Sort Data :

ADO Sort data with examples. We may use SQL to specify how to sort the data in the record set.

The Sort property sets or returns a string value that specifies the field names in the Recordset to sort on. Each field name must be separated by a comma. To choose the sort order, you can specify ASC (ascending order), or DESC (descending order) after the field name. Default is ASC.

Note: This property can only be used if the CursorLocation property is set to adUseClient.

ADO Sort data

Sort the Data

We want to display the “Companyname” and “Contactname” fields from the “Customers” table, ordered by “Companyname” (remember to save the file with an .asp extension):



set conn=Server.CreateObject(“ADODB.Connection”)
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%”>
<%for each x in rs.Fields
response.write(“<th>” & & “</th>”)
<%do until rs.EOF%>
<%for each x in rs.Fields%>



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.