order by `字段` desc(降序,默认为升序!)

解决方案 »

  1.   

    我这样写是错的
    ors.Sql="id,aaaa,bbbb,cccc,dddd,eeee$table1 where eeee='"&rr&"'order by id desc" '字段,表,条件(需要where),排序,主IDors.Sql="id,aaaa,bbbb,cccc,dddd,eeee$table1 where eeee='"&rr&"'$$$id desc" '字段,表,条件(需要where),排序,主ID
      

  2.   

    "select .... from $table1 where eeee=.. order by id"
      

  3.   

    改成这样还是错啊
    sql="select id,aaaa,bbbb,cccc,dddd,eeee from $table1 where eeee='"&rr&"' order by id desc"
      

  4.   

    try:$sql = "select id,aaaa,bbbb,cccc,dddd,eeee from $table1 where eeee='&rr&' order by id desc";
      

  5.   

    是的啊。我把代码贴出来。大家看下是怎么回事,一共两个页page.asp  Cls_Pages.asppage.asp:<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
    <!--#include file="Cls_Pages.asp"-->
    <%
    On Error Resume Next
    DIM startime,endtime
    '统计执行时间
    startime=timer()
    '连接数据库
    DIM Db,Conn,Rs
    Db = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("./db.mdb")
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.open Db
    '-----------------------------------------------------------------------------------------------
    %>
    <html>
    <head>
    <title>Access高效分页类</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    body,table,td,p,li {font-size:9pt}
    a {font-size:12px;color:#000000;text-decoration: none}
    INPUT {
    BORDER-TOP-WIDTH: 1px;
    PADDING-RIGHT: 1px;
    PADDING-LEFT: 1px;
    BORDER-LEFT-WIDTH: 1px;
    FONT-SIZE: 12px;
    BORDER-LEFT-COLOR: #cccccc;
    BORDER-BOTTOM-WIDTH: 1px;
    BORDER-BOTTOM-COLOR: #cccccc;
    PADDING-BOTTOM: 1px;
    BORDER-TOP-COLOR: #cccccc;
    PADDING-TOP: 1px;
    HEIGHT: 18px;
    BORDER-RIGHT-WIDTH: 1px;
    BORDER-RIGHT-COLOR: #cccccc;
    BACKGROUND-COLOR: #F2F8FF
    }
    -->
    </style>
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <table width="760" border="0" cellspacing="2" cellpadding="2" align="center" height="30">
      <tr> 
        <td>&nbsp;</td>
      </tr>
    </table>
    <table width="760" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#FFFFFF" bordercolorlight="#CCCCCC">
      <tr align="center"> 
        <td width="60">ID</td>
        <td width="150">标题</td>
        <td width="*">内容(显示前20个字)</td>
        <td width="150">时间</td>
      </tr>
    <%
    Set ors=new Cls_Pages   '创建对象
    ors.Conn=conn    '得到数据库连接
    ors.RecPerPage=30 '每页记录条数
    ors.CookieName="table1"    '存记录总数的cookiesname
    ors.PageUrl=""    'showo_page.js的路径
    ors.Term=0    '条件是否有变化(0无变化,1有变化,2不设置cookies也就是及时统计)
    rr="tt"
    ors.Sql="id,aaaa,bbbb,cccc,dddd,eeee $table1 where eeee='"&rr&"'$$$id" '字段,表,条件(需要where),排序,主ID
    'sql="select id,aaaa,bbbb,cccc,dddd,eeee from $table1 where eeee='"&rr&"' order by id"iRecCount=ors.RecCount() '记录总数
    iRs=ors.ResultSet()    '返回ResultSet
    If  iRecCount<1 Then%>
    <tr bgcolor=""> 
        <td >暂无记录</td>    
      </tr>
    <%
    Else     
        For i=0 To Ubound(iRs,2)
    bgColor="#FFFFFF"
    if i mod 2=0 then bgColor="#DFEFFF"
    %>
      <tr bgcolor="<%=bgColor%>"> 
        <td width="60"><%=iRs(0,i)%></td>
        <td width="150"><%=iRs(1,i)%></td>
        <td width="*"><%=left(iRs(2,i),20)%></td>
        <td width="150"><%=iRs(3,i)%></td>
      </tr><%
        Next
    End If
    %>
    </table>
    <table width="760" border="0" cellspacing="2" cellpadding="2" align="center">
      <tr> 
        <td>
    <%ors.ShowPage()%>
    </td>
      </tr>  
    </table> 
    <table width="760" border="0" align="center" cellpadding="2" cellspacing="2">
      <tr> 
        <td align="center"> 
          <%endtime=timer()%>
          本页面执行时间:<%=round((endtime-startime)*1000,3)%>&nbsp;毫秒</td>
      </tr>
    </table>
    </body>
    </html>
    <%
    iRs=NULL
    ors=NULL
    Set ors=NoThing
    %>
      

  6.   

    Cls_Pages.asp:
    <%
    Class Cls_Pages
        Rem Const
        Private Showo_RecPerPage,Showo_CurrPage
        Private Showo_Conn,Showo_CookieName,Showo_PageUrl,Showo_Term
        Private Showo_Sql,Showo_Field,Showo_Table,Showo_Where,Showo_OrderBy,Showo_Id
        Private iRecCount,iPageCount,iCurrPage,ResultSet_Sql,Showo_Mm     '================================================================
        ' Class_Initialize 类的初始化
        '================================================================
        Private Sub Class_Initialize
            Showo_RecperPage=10  '设定每页记录条数的默认值为10 
            Showo_CurrPage=CheckNum(Trim(request("Page")),1,-1) '获取当前面的值
        End Sub    '================================================================
        ' Conn  得到数据库连接
        '================================================================ 
        Public Property Let Conn(obj_conn)
            Set Showo_Conn=obj_conn
        End Property    '================================================================
        ' RecperPage 设置每一页记录条数,默认10记录
        '================================================================
        Public Property Let RecPerPage(ByVal int_recperpage)
            Showo_RecPerPage=CheckNum(int_recperpage,10,-1) 
        End Property    '================================================================
        ' CookieName 取得cookiename
        '================================================================
        Public Property Let CookieName(ByVal str_cookiename)
            Showo_CookieName=str_cookiename  
        End Property    '================================================================
        ' PageUrl 取得showo_page.js的路径
        '================================================================
        Public Property Let PageUrl(ByVal str_pageurl)
            Showo_PageUrl=str_pageurl
        End Property    '================================================================
        ' Term 搜索条件是否变化(0无变化,1有变化)
        '================================================================
        Public Property Let Term(ByVal int_term)
            Showo_Term=CheckNum(int_term,0,1) 
        End Property    '================================================================
        ' Sql 取得sql所需表字段条件排序,输入:字段,表,条件,排序,主ID
        '================================================================
        Public Property Let Sql(ByVal str_sql)  
            Showo_Sql=Split(str_sql,"$")
            Showo_Field=Showo_Sql(0)
            Showo_Table=Showo_Sql(1)
            Showo_Where=Showo_Sql(2)
            Showo_OrderBy=Showo_Sql(3)
            Showo_Id=Showo_Sql(4) 
        End Property    '================================================================
        ' RecCount 取得记录总数
        '================================================================
        Public Property Get RecCount()
            If Showo_Term=0 Then
                RecCount=Request.Cookies("ShowoPage")(Showo_CookieName)
                RecCount=CheckNum(RecCount,0,-1) 
                If RecCount=0 Then
                RecCount=Showo_Conn.execute("SELECT Count("&Showo_Id&") FROM "&Showo_Table&" "&Showo_Where,0,1)(0)       
                Response.Cookies("ShowoPage")(Showo_CookieName)=RecCount
                End If   
            ElseIf Showo_Term=1 Then
                RecCount=Showo_Conn.execute("SELECT Count("&Showo_Id&") FROM "&Showo_Table&" "&Showo_Where,0,1)(0) 
            Response.Cookies("ShowoPage")(Showo_CookieName)=RecCount
            Else
                RecCount=Showo_Conn.execute("SELECT Count("&Showo_Id&") FROM "&Showo_Table&" "&Showo_Where,0,1)(0) 
            End If     
        End Property    '================================================================
        ' ResultSet 返回分页后的记录集
        '================================================================
        Public Property Get ResultSet()  
            ResultSet=Null  
            '记录总数
            iRecCount=RecCount()   
            '当前页
            If iRecCount>0 Then
                '页数
                If (iRecCount mod Showo_RecPerPage)=0 Then
                    iPageCount=iRecCount\Showo_RecPerPage  
                Else
                    iPageCount=iRecCount\Showo_RecPerPage+1 
                End If
                '当前页
                iCurrPage=CheckNum(Showo_CurrPage,1,iPageCount) 
            Set Showo_Rs = server.CreateObject ("adodb.RecordSet")
            ResultSet_Sql="SELECT "&Showo_Field&" FROM "&Showo_Table&" "&Showo_Where&" "&Showo_OrderBy
                Showo_Rs.Open ResultSet_Sql,Showo_Conn,1,1,&H0001
            '&H0001表示adCmdText,将执行一段sql,&H0002表示adCmdTable,将操作一个表
            Showo_Rs.AbsolutePosition=(iCurrPage-1)*Showo_RecPerPage+1     
                ResultSet=Showo_Rs.GetRows(Showo_RecPerPage) 
    Showo_Rs.close
                Set Showo_Rs=nothing
            End If  
        End Property    '================================================================
        ' 输入:检查字段,开始数字(默认数字),结束数字(为-1则不检查大小)
        '================================================================
        Private Function CheckNum(byval iStr,byval iStartNum,byval iEndNum)  
            If IsNumeric(iStr) Then
                CheckNum=Clng(iStr)
            Else
                CheckNum=iStartNum
            End If
            If iEndNum>-1Then
                If CheckNum<iStartNum Then CheckNum=iStartNum
                If CheckNum>iEndNum Then CheckNum=iEndNum   
            End If  
        End Function    '================================================================
        ' Class_Terminate 类注销
        '================================================================
        Private Sub Class_Terminate()  
            If IsObject(Showo_Conn) Then 
            Showo_Conn.Close
            Set Showo_Conn = Nothing
            End If   
        End Sub    '================================================================
        ' 上下页部分
        '================================================================
        Public Sub ShowPage()%>
            <Script Language="JavaScript" type="text/JavaScript" src="<%=Showo_PageUrl%>showo_page.js"></Script>
            <Script Language="JavaScript">
    ShowoPage("<table border='0' cellspacing='0' width='100%'><tr><td vAlign='bottom'  style='font-family:Verdana,宋体;font-size:8pt;line-height:15px'>","</td></tr></table>","页次:<font color='red'>","</font>/","","&nbsp;","&nbsp;每页<font color='red'>","</font>&nbsp;","&nbsp;共计:<font color='red'>","</font></td><td vAlign='bottom' align='right' style='font-family:Verdana,宋体;font-size:8pt;line-height:15px'>","<font face=webdings>9</font>","<font face=webdings>7</font>","<font face=webdings>8</font>","<font face=webdings>:</font>","&nbsp;&nbsp;跳转:","<font color='orange'>[","]</font>","","","<font color='red'>","</font>","","",<%=RecCount()%>,<%=Showo_RecperPage%>,2)
            </Script>
        <%End SubEnd Class
    %>
      

  7.   

    page.asp 里这段sql  
     ors.Sql="id,aaaa,bbbb,cccc,dddd,eeee $table1 where eeee='"&rr&"'$$$id" '字段,表,条件(需要where),排序,主ID
    是调用了Cls_Pages.asp里的Public Property Get ResultSet()。 但我改了很多种方法,还是改不出升序,降序的切换