0
在代碼隱藏中,我想爲entitydatasource應用動態where子句,但我希望這樣的地方能夠像和不相等。我有這樣的代碼工作,這是相等的我想要一個等價的代碼,以某種方式將其轉換爲Like語句。如何使用WhereParameters和EntityDataSource執行Like類型查詢
的XAML:
<WhereParameters>
<asp:ControlParameter ControlID="tbxSearch" Name="Name" Type="String" />
</WhereParameters>
代碼背後:(負載事件)
if (string.IsNullOrEmpty(tbxSearch.Text))
{
this.EntityDataSource1.Where = "1=1"; //fetch all data if empty
}
else
{
this.EntityDataSource1.Where = "it.Name like '%' + @Name + '%'"; //filter
}
以及我想這樣做在後面的代碼...因爲我需要過濾特定事件的數據源... – rtp 2012-07-19 09:04:15
應用相同的邏輯,因爲'Where'屬性是'string',你可以在後面的代碼中分配where條件,檢查我更新的響應 – Jupaol 2012-07-19 09:08:07
我得到這個錯誤:查詢語法無效。附近標識符'abcd' – rtp 2012-07-19 09:11:03