ADO Sort Data

ADO Sort Data

 

We may use SQL to specify how to sort the data in the record set.


Sort the Data

Here 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.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)%>



Here we want to display the "Companyname" and "Contactname" fields from the "Customers" table, ordered descending by "Companyname" (remember to save the file with an .asp extension):




<%
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 DESC"
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)%>


 
ADO Sort

Login
ADS CODE