Runoob Tutorial ArchiveEnglish

ADO Sorting

ADO Sorting


We can use SQL to specify how to sort the data in a recordset.


Sorting data

We want to display the "Companyname" and "Contactname" fields from the "Customers" table, and sort by "Companyname" (please remember to save with the .asp extension):

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 ORDER BY CompanyName"

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 Showcase »


More Instances

Sort records in descending order based on the specified field name
How to sort data based on a specified field name

Allow the user to choose which column to sort by
Allow the user to choose which column to sort by