ADO Sắp xếp
Chúng tôi có thể sử dụng SQL để chỉ định cách sắp xếp dữ liệu trong tập bản ghi.
Sắp xếp dữ liệu
Chúng tôi muốn hiển thị các trường "Tên công ty" và "Tên liên hệ" từ bảng "Khách hàng", được sắp xếp theo "Tên công ty" (hãy nhớ lưu tệp với phần mở rộng .asp):
Thí dụ
<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>
Các ví dụ khác
Cách sắp xếp dữ liệu trên một tên trường cụ thể.
Cho phép người dùng chọn cột để sắp xếp.