2012-02-03 65 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