我有一個搜索條件,以基於兩種信息來查找有關車輛的信息。第一個是容器名稱和自定義聲明一個搜索按鈕和兩個文本框如果語句邏輯
我有一個帶有文本搜索和兩個文本框的按鈕,第一個文本是容器名稱,第二個是自定義聲明。
我使用EF加入三個表與包含這樣的:
var query = (from con in db.Containers
join v in db.Vehicles on con.cont_vehicleid equals v.vehl_VehicleID
join cust in db.Custom_Captions on v.vehl_state equals cust.Capt_Code
where cust.Capt_Family == "vehl_state" && v.vehl_Deleted == null && con.cont_Deleted == null &&
v.vehl_ClearanceCompany == p.pusr_CompanyId && con.cont_Name.Contains(txtContNo.Text)
select new
{
cont_name = con.cont_Name,
vehl_Name = v.vehl_Name,
VehicleState = v.vehl_state,
vehl_drivername = v.vehl_drivername,
vehl_entrancedate = v.vehl_entrancedate,
vehl_customsdec = v.vehl_customsdec,
cont_rampid = v.vehl_rampid
}).ToList();
var query2 = (from con in db.Containers
join v in db.Vehicles on con.cont_vehicleid equals v.vehl_VehicleID
join cust in db.Custom_Captions on v.vehl_state equals cust.Capt_Code
where cust.Capt_Family == "vehl_state" && v.vehl_Deleted == null && con.cont_Deleted == null &&
v.vehl_ClearanceCompany == p.pusr_CompanyId && con.cont_customdec.Contains(txtCust.Text)
select new
{
cont_name = con.cont_Name,
vehl_Name = v.vehl_Name,
VehicleState = v.vehl_state,
vehl_drivername = v.vehl_drivername,
vehl_entrancedate = v.vehl_entrancedate,
vehl_customsdec = v.vehl_customsdec,
cont_rampid = v.vehl_rampid
}).ToList();
與第一查詢包含容器名稱條件(txtContNo.Text)
與第二QUERY2包含條件表單容器名稱(txtCust.Text)
這是我用來處理執行哪個查詢的if語句:
if (txtContNo.Text != null)
{
rptVehl.DataSource = query;
rptVehl.DataBind();
}
if (txtCust.Text != null)
{
rptVehl.DataSource = query2;
rptVehl.DataBind();
}
rptVehl是中繼器工具
我每次編譯代碼中沒有錯誤,但是當我在(txtContNo.Text)輸入容器名稱沒有出現數據,也當我使用的跟蹤點的代碼首先如果屬於(txtContNo.Text)的語句沒有命中。
當我輸入自定義聲明它工作並給我關於我搜索的數據?
請注意:如果我省略第一個if語句,第二個工作正常 並給我所需的輸出。
我認爲if邏輯有問題。有人可以弄清楚嗎?
您可以查詢一般爲兩個條件。如果用戶在兩個文本框中輸入值,那麼你的if邏輯將不起作用。 –
@SanthoshNayak我該怎麼做,請解釋一下? –
放入斷點並檢查txtContNo中是否有值。當你搜索文本 –