我正在關注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