我正在关注列出的可搜索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/