Sắp xếp ADO
- Trang trước Truy vấn ADO
- Trang tiếp theo Thêm ADO
Chúng ta có thể sử dụng SQL để quy định cách sắp xếp dữ liệu trong tập ghi lại.
Mẫu
- Sắp xếp ghi lại theo thứ tự tăng dần theo tên trường cụ thể
- Cách sắp xếp dữ liệu theo tên trường cụ thể
- Sắp xếp ghi lại theo thứ tự giảm dần theo tên trường cụ thể
- Cách sắp xếp dữ liệu theo tên trường cụ thể
- Cho phép người dùng chọn cột nào để sắp xếp
- Cho phép người dùng chọn cột nào để sắp xếp
Sắp xếp dữ liệu
Chúng tôi muốn hiển thị các trường "Companyname" và "Contactname" trong bảng "Customers" và sắp xếp theo "Companyname" (hãy nhớ lưu với đuôi .asp):
<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>
- Trang trước Truy vấn ADO
- Trang tiếp theo Thêm ADO