我正在关注THIS解决方案,以使gridview可搜索。这似乎与工作非常接近,但当我尝试搜索时,我无法弄清楚:below:exception。任何想法将不胜感激。ASP.NET可搜索GridView异常
protected void BindSGVData()
{
//hfSearchText has the search string returned from the grid.
if (hfSearchText.Value != "")
RidesSQL.SelectCommand += " where " + hfSearchText.Value;
DataView dv = (DataView)RidesSQL.Select(new DataSourceSelectArguments()); //EXCEPTION HERE!!!
//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;
}
}
例外:关键字 '其中' 附近
不正确的语法。
- > hfSearchText.Value载:“名称,如‘斯宾塞%’”
查询的条件是什么?这似乎是这样。 “选择价值”。它必须是这样的。 “Select [fields] where [field] .ColumnName = value” – fiberOptics 2012-02-02 01:37:19
看起来代码生成的查询看起来像:“SELECT * FROM [Rides] ORDER BY [TimeOfCall],[Status]其中名称如'Spencer%' “......但我似乎无法弄清楚究竟要改变什么。 – SHeinema 2012-02-02 04:47:35