C#:SQL FilterExpression - 缺少操作数异常

标签 c# asp.net sql search sqldatasource

我正在关注列出的可搜索gridview代码HERE 。我在使用 FilterExpression 时遇到问题。我得到了异常(exception):

Missing operand after 'Name' operator... When the exception occurs, 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;
            }
        }

有什么想法吗?

最佳答案

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

应该是:

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

关于C#:SQL FilterExpression - 缺少操作数异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9122526/

相关文章:

c# - 使 SSL 连接可配置

c# - 已经用相同的参数类型定义了一个名为 'InitializeComponent' 的成员

asp.net - Razor View 无法识别 @model 或 Lambda @Html 方法

mysql - WEBSQL 简单插入填充表

sql - SELECT 不返回数值

sql - Datetime 的哪个 Where 条件会更快?

c# - 与资源字典共享项目 (xaml)

c# - 新的关键字和方法隐藏

asp.net - 我在使用 asp.net MVC 4 时遇到一些编码问题,其中某些字符(如撇号)显示为“

mysql - 试图将值插入数据库