当前位置: 首页 > 网络学院 > 服务端脚本教程 > ADO > ADO记录排序

ADO
ADO DataTypes
ADO 摘要
ADO 实例

ADO 中的 ADO记录排序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 963 ::
收藏到网摘: n/a

We may use SQL to specify how to sort the data in the record set. 
我们可以使用SQL来指明每条记录中数据的排列顺序


Examples
案例

Sort the records on a specified fieldname ascending
将记录中指定的字段名按升序排列
How to sort the data on a specified fieldname.
如何将数据按照指定的字段名进行排列。

Sort the records on a specified fieldname descending
将记录中指定的字段名按降序排列
How to sort the data on a specified fieldname.
如何将数据按照指定的字段名进行排列。

Let the user choose what column to sort on
让用户选择需要对哪一纵列进行排列
Let the user choose what column to sort on.
让用户选择需要对哪一纵列进行排列


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):
我们希望对“Customers”表格中的名为"Companyname" 和"Contactname"的字段所对应的数据以"Companyname"字段名开头字母的顺序为基准进行排列(记住:使用“.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>

Here is the result:
输出结果:

Companyname Contactname
Alfreds Futterkiste Maria Anders
Berglunds snabbköp Christina Berglund
Centro comercial Moctezuma Francisco Chang
Ernst Handel Roland Mendel
FISSA Fabrica Inter. Salchichas S.A. Diego Roel
Galería del gastrónomo Eduardo Saavedra
Island Trading Helen Bennett
Königlich Essen Philip Cramer
Laughing Bacchus Wine Cellars Yoshi Tannamuri
Magazzini Alimentari Riuniti Giovanni Rovelli
North/South Simon Crowther
Paris spécialités Marie Bertrand
Rattlesnake Canyon Grocery Paula Wilson
Simons bistro Jytte Petersen
The Big Cheese Liz Nixon
Vaffeljernet Palle Ibsen
Wolski Zajazd Zbyszek Piestrzeniewicz

评论 (2) 1 All

登陆 | 还没注册?