【发布时间】:2012-02-02 00:05:29
【问题描述】:
我正在关注 THIS 解决方案,以使 gridview 可搜索。它似乎非常接近工作,但是当我尝试搜索时,我无法弄清楚 :below: 异常。任何想法将不胜感激。
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;
}
}
例外:
关键字“where”附近的语法不正确。
-> hfSearchText.Value 包含:“Name like 'Spencer%'”
【问题讨论】:
-
查询的条件是什么?看起来是这样的。 “选择价值”。它必须是这样的。 "选择 [fields] where [field].ColumnName = value"
-
看起来代码正在生成如下查询:“SELECT * FROM [Rides] ORDER BY [TimeOfCall], [Status] where Name like 'Spencer%'”...但我可以似乎不知道要改变什么。
标签: c# asp.net sql gridview where-clause