【问题标题】:C#: SQL FilterExpression - Missing Operand ExceptionC#:SQL FilterExpression - 缺少操作数异常
【发布时间】:2012-02-25 17:01:30
【问题描述】:

我正在关注HERE 列出的可搜索网格视图代码。我在使用FilterExpression 时遇到问题。我得到了例外:

“名称”运算符后缺少操作数...发生异常时, FilterExpression = " WHERE Name like 'spencer%'"

异常发生在以下代码中:

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;
            }
        }

有什么想法吗?

【问题讨论】:

  • @M.Babcock 你先生是我的英雄!大声笑,这里是为了不抓住明显的...我已经将它从编辑选择命令更改为添加过滤器,是的,不需要 WHERE.. 我太忙于修改操作数而没有注意到。必须回答一个答案,这样我就可以给你一个大的绿色复选标记! ( :

标签: c# asp.net sql search sqldatasource


【解决方案1】:
RidesSQL.FilterExpression = " WHERE " + hfSearchText.Value; //EXCEPTION HERE!

应该是:

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

【讨论】:

  • 完成 +1 Sheinema 如果这对您有帮助,请将此标记为您的答案
  • @Rofans.NET - 非常感谢 :)
猜你喜欢
  • 2020-01-05
  • 2012-09-29
  • 1970-01-01
  • 2020-09-22
  • 2016-02-09
  • 1970-01-01
  • 2018-04-05
  • 1970-01-01
  • 2010-10-17
相关资源
最近更新 更多