//取得查询条件
txtQueryCondition.Value="";
string condition="";
txtNavigatePage.Value="block";
 
//分类
string categoryId=CommonMethod.GetRequest(this,"categoryId");
if(categoryId.Length>0)
{
// this.txtCategoryId.Value=categoryId;
if(categoryId.IndexOf(",")>0)//因为URLRewriter请求页面/Search/product_3403.html形式时,会造成categoryId重复两次
{
categoryId=categoryId.Substring(0,categoryId.IndexOf(","));
}
condition+=" and ( A.industryType1='"+categoryId+"' or  A.industryType2='"+categoryId+"' or  A.industryType3='"+categoryId+"'  )";
}
else
{
this.dtCategory.Visible=false;
}
string province =CommonMethod.GetRequest(this,"province");
if(province.Length>0)
{
condition+="  and A.province='"+province+"' ";
}
string city =CommonMethod.GetRequest(this,"city");
if(city.Length>0)
{
condition+="  and A.city='"+city+"' ";
}
string businesstype =CommonMethod.GetRequest(this,"businesstype");
if(businesstype.Length>0)
{
condition+="  and A.businesstype = '"+businesstype+"' ";
}
string foundDate =CommonMethod.GetRequest(this,"founddate");

if(foundDate.Length>0)//发布时间
{

condition+="  and A.Creationtime>getdate()-"+foundDate;
}

string keyword =CommonMethod.GetRequest(this,"keyword");
if(keyword.Length>0)
{
condition+="  and contains(A.OfferTitle , '"+keyword+"') ";
this.txtKeyword.Value=keyword;
} string keywords =CommonMethod.GetRequest(this,"keywords");

if(keywords.Length>0)
{
condition+="  and contains(A.OfferTitle , '"+keywords+"') ";
this.txtKeyword.Value=keywords;
}

//每页数量
int pageSize=10;
if(CommonMethod.GetRequest(this,"pageSize").Length>0)
{
pageSize=System.Int16.Parse(CommonMethod.GetRequest(this,"pageSize"));
}
this.AspNetPager1.PageSize=pageSize;
 

this.txtPageSize.Value=pageSize.ToString(); string showType="2";
if(CommonMethod.GetRequest(this,"showType").Length>0)
{
showType=CommonMethod.GetRequest(this,"showType");
}
this.txtShowType.Value=showType;
// string sql="select A.*,B.gid,B.zoneid from t_offer A left join t_lavauser B on (A.CreatedByUserId=B.lavauserId) where  A.IsDeleted=0 and A.IsBuy=0"; //string osql = " group by  a.CreationTime ";
sql+=condition;
//sql += osql;
DataSet ds=ServiceInterfaces.CommonService.GetDataPage(sql,this.AspNetPager1.CurrentPageIndex,this.AspNetPager1.PageSize,out ResultRecordCount);
遇到的问题:如何在string sql中加入按时间addtime排序呢?用order by 好像不行,谢谢帮忙,谢谢

解决方案 »

  1.   

    在后面加上
    order by A.Creationtime 不行吗?
      

  2.   

    我看你注销掉的是group by而不是order by
      

  3.   

    查了下contains你这用order by可行吧。你把拼出来的sql在查询分析器里运行下看看。。
      

  4.   

    ...........inner join t_lavauser B on...........where.........order by A.addtime
      

  5.   

    不应该是order by 的问题
      

  6.   

     
                if(foundDate.Length>0)//发布时间
                {
                    
                    condition+="  and A.Creationtime>getdate()-"+foundDate;
                }这里出的问题吧
      

  7.   

    除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。
      

  8.   

    sql放数据库里执行没错,可是DataSet ds=ServiceInterfaces.CommonService.GetDataPage(sql,this.AspNetPager1.CurrentPageIndex,this.AspNetPager1.PageSize,out ResultRecordCount);就有错,
    错误是:除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。
    求救,谢谢