C#:SQL FilterExpression-缺少操作数异常
本文关键字:操作数 异常 FilterExpression- SQL | 更新日期: 2023-09-27 18:22:14
我正在关注此处列出的可搜索网格视图代码。我在使用FilterExpression
时遇到问题。我得到了一个例外:
"Name"运算符后缺少操作数。。。当异常发生时,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!