·您的位置: 首页 » 资源教程 » 编程开发 » ASP » 菜鸟学ADO实例教程之ADO 排序数据

菜鸟学ADO实例教程之ADO 排序数据

类别: ASP教程  评论数:0 总得分:0
 我们可以用SQL使记录按顺序显示:

  我们想显示"Companyname" 和 "Contactname" 字段的内容,并且按"Companyname"进行排序显示:

  <html>

  <body>

  <%

  set conn=Server.CreateObject("ADODB.Connection")

  conn.Provider="Microsoft.Jet.OLEDB.4.0"

  conn.Open "e:/webjx/webjx.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>

  我们想显示"Companyname" 和 "Contactname" 字段的内容,并且按"Companyname"进行倒序显示:

  <html>

  <body>

  <%

  set conn=Server.CreateObject("ADODB.Connection")

  conn.Provider="Microsoft.Jet.OLEDB.4.0"

  conn.Open(Server.Mappath("e:/webjx/webjx.mdb"))

  set rs = Server.CreateObject("ADODB.recordset")

  sql="SELECT Companyname, Contactname FROM Customers ORDER BY CompanyName DESC"

  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>

  按用户的需求自己选择排序方式,比如按公司名称或联系人排序:(把下面文件保存为demo_sort.asp )

  <html>

  <body>

  <table border="1" width="100%" bgcolor="#fff5ee">

  <tr>

  <th align="left" bgcolor="#b0c4de">

  <a href="demo_sort.asp?sort=companyname">公司名</a>

  </th>

  <th align="left" bgcolor="#b0c4de">

  <a href="demo_sort.asp?sort=contactname">联系人</a>

  </th>

  </tr>

  <%

  if request.querystring("sort")<>"" then

    sort=request.querystring("sort")

  else

    sort="companyname"

  end if

  set conn=Server.CreateObject("ADODB.Connection")

  conn.Provider="Microsoft.Jet.OLEDB.4.0"

  conn.Open(Server.Mappath("e:/webjx/webjx.mdb"))

  set rs=Server.CreateObject("ADODB.recordset")

  sql="SELECT Companyname,Contactname FROM Customers ORDER BY " & sort

  rs.Open sql,conn

  do until rs.EOF

    response.write("<tr>")

    for each x in rs.Fields

     response.write("<td>" & x.value & "</td>")

    next

    rs.MoveNext

    response.write("</tr>")

  loop

  rs.close

  conn.close

  %>

  </table>

  </body>

  </html>
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1