我有一個Gridview,我想過濾。我的gridview是在更新面板中,我的過濾器按鈕不是。在按鈕點擊我有以下內容追加到選擇命令
protected void bttnfilter_Click(object sender, ImageClickEventArgs e)
{
if (TextBox1.Text != "")
{
SqlDataSource1.SelectCommand += " and field like '%' + @param + '%'";
SqlConnection conn = new SqlConnection(SqlDataSource1.ConnectionString);
SqlCommand cmd = new SqlCommand(SqlDataSource1.SelectCommand, conn);
cmd.Parameters.Add(new SqlParameter("@param", TextBox1.Text));
}
}
因此,我添加到選擇命令,但我得到一個錯誤。我應該怎麼做呢?我不想使用動態SQL。
的錯誤讀取 附近有語法錯誤「和」
「我得到一個錯誤」你得到了什麼錯誤? – Welbog 2009-09-18 16:14:31
錯誤的語法靠近'和' – Eric 2009-09-18 16:16:47
什麼是最初的'SelectCommand'的值? – Welbog 2009-09-18 16:17:51