2012-02-03 36 views
2

我正在关注可搜索的网格视图代码HERE。我在使用FilterExpression时遇到问题。我得到异常:C#:SQL FilterExpression - 缺少操作数异常

缺少操作数“名称”操作...当发生异常时, FilterExpression =“WHERE名称如‘斯宾塞%’”

唯一的例外发生在以下代码:

protected void BindSGVData() 
     { 
      //hfSearchText has the search string returned from the grid. 
      if (hfSearchText.Value != "") 
      { 
       RidesSQL.FilterExpression = " WHERE " + hfSearchText.Value; //EXCEPTION HERE! 
      } 
      DataView dv = (DataView)RidesSQL.Select(new DataSourceSelectArguments()); 
      //hfSort has the sort string returned from the grid. 
      if (hfSort.Value != "") 
      { 
       dv.Sort = hfSort.Value; 
      } 

      RideSGV.DataSource = dv; 
      try 
      { 
       RideSGV.DataBind(); 
      } 
      catch (Exception exp) 
      { 
       //If databinding threw exception bcoz current page index is > than available page index 
       RideSGV.PageIndex = 0; 
       RideSGV.DataBind(); 
      } 
      finally 
      { 
       //Select the first row returned 
       if (RideSGV.Rows.Count > 0) 
        RideSGV.SelectedIndex = 0; 
      } 
     } 

有什么想法?

+0

您正在使用什么数据库? – 2012-02-03 01:29:57

+0

@ M.Babcock你先生是我的英雄!大声笑,这里是不捕捉明显的...我已经改变了编辑选择命令添加一个过滤器,并且yup不需要在哪里..我太赶上修改操作数注意。得到答复回答,所以我可以给你一个大胖绿色的复选标记! (: – SHeinema 2012-02-03 01:31:04

回答

6
RidesSQL.FilterExpression = " WHERE " + hfSearchText.Value; //EXCEPTION HERE! 

应该是:

RidesSQL.FilterExpression = hfSearchText.Value; // NO EXCEPTION HERE! 
+0

这就是答案 – rofans91 2012-02-03 01:37:12

+0

done +1 Sheinema pls将此标记为您的答案,如果这有助于您 – rofans91 2012-02-03 01:41:33

+0

@ Rofans.NET - 非常感谢:) – 2012-02-03 01:43:04