2012-02-03 2 views
2

HEREと記載されている検索可能なgridviewコードに従っています。 FilterExpressionの使用に問題があります。例外が発生した場合...「名前」演算子の後C#:SQL FilterExpression - 不足しているオペランド例外

オペランドがありませんが、「『スペンサー%』のような名前」

は、例外が次で発生し FilterExpression =:私は例外を取得しますコード:

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

あなたはどのようなデータベースを使用していますか? –

+0

@ M.Babcockあなたは私のヒーローです! Lolは、ここにはっきりとしたことを理解しないことです...私はselectコマンドを編集してフィルタを追加するように変更しました。そして、それはどこにも必要ありません。私はあまりにもオペランドを修正することに気付いていました。私はあなたに大きな太った緑色のチェックマークを与えることができるので、答えを返せ! (: – SHeinema

答えて

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

は次のようになります。

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

これはまさに答えです。 – rofans91

+0

完了+1 Sheinema plsがこれを助けてくれると回答します – rofans91

+0

@ Rofans.NET - ありがとうございます:) –