我在页面间传值出错,出错提示:字符串的语法错误 在查询表达式 'Category='酱油?order by ProductID DESC' -------------
    我是在做同一个页面不同类型的产品显示不同的内容,我是用类型Category传值的,不过不知道什么原因,如果是传“粉类”,“汤类"就可以,但是我一传“酱油类”,它就报上面的错误。在新闻类型的传值中也出现这个问题,请问有谁知道什么原因啊,可以告诉一下吗,小弟万分感激!

解决方案 »

  1.   


    public OleDbDataReader ProductList()
    {
    myConnection=new OleDbConnection(ConfigurationSettings.AppSettings["ConnectionString"]+System.Web.HttpContext.Current.Server.MapPath("yuelong.mdb"));
     
    string strSQL="Select * From Product Where Category="+ System.Web.HttpContext.Current.Request.QueryString["Category"].Trim().ToString+"order by ProductID DESC";
    OleDbCommand myCommand=new OleDbCommand(strSQL,myConnection); OleDbDataReader dr=null;
    try
    {
    myConnection.Open();
    dr=myCommand.ExecuteReader();
    }
    catch(Exception ex)
    {
    throw new Exception(ex.Message,ex);
    }


    return dr;


    }-----------------------
    这是我在类中做的显示不同类型产品的部分代码错误提示如下:
    字符串的语法错误 在查询表达式 'Category='酱油?order by ProductID DESC' 中。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: 字符串的语法错误 在查询表达式 'Category='酱油?order by ProductID DESC' 中。源错误: 
    行 167: {
    行 168: myConnection.Open();
    行 169: dr=myCommand.ExecuteReader();//错误行
    行 170: }
    行 171: catch(Exception ex)
     
      

  2.   

    LZ改成这样看看行不行:
    public OleDbDataReader ProductList()
    {
    myConnection=new OleDbConnection(ConfigurationSettings.AppSettings["ConnectionString"]+System.Web.HttpContext.Current.Server.MapPath("yuelong.mdb"));
     
    string strSQL="Select * From Product Where Category="+ System.Web.HttpContext.Current.Request.QueryString["Category"].Trim().ToString+" order by ProductID DESC";    //这里多加一个空格,也就是+" order by ProductID DESC",
    OleDbCommand myCommand=new OleDbCommand(strSQL,myConnection);......
      

  3.   

    ...
    Request.QueryString["Category"].Trim().ToString+"order by ProductID DESC"; 
    ...
    也就是把这句改成下面的样子看看行不呢?即在 "和order之间加一个空格.
    ...
    Request.QueryString["Category"].Trim().ToString+" order by ProductID DESC"; 
    ...
      

  4.   

    order by 前面加个空格就行了。
      

  5.   

    把这句话copy到你原来的位子试试:string strSQL="Select * From Product Where Category='"+ System.Web.HttpContext.Current.Request.QueryString["Category"].toString().Trim()+"'  order by ProductID DESC";
      

  6.   

    有没有用函数处理Request.QueryString()的输入?如果有查一下是不是处理有误.
      

  7.   

    建议你单步调试下看看你的sql语句是怎么样的!!!能否执行正确?
      

  8.   

    另外建议你url传值不要用中文很容易报错的,还不如传个编码值(食品编码,食品名)!