过滤条件的问题
按下面这段代码,如果一个过滤条件为空。程序会报错,怎么能解决呢?
//dw_1.DataObject = "zuihouxiaoshoujiluchaxun"
//dw_1.DataObject = "xiaoshoujiluguanli"
dw_1.DataObject = "xiaoshouchaxun"
dw_1.visible = true
string sffk ,khmc,null_str//是否付款,客户名称
if ddlb_1.text <>"" then
sffk = "settleaccounts='" + string(ddlb_1.text) +"'"
//dw_1.setfilter(sffk)//根据sffk设置过滤条件
end if
if ddlb_2.text <>"" and ddlb_3.text <>''then
khmc = "client_clientname = '" + string(ddlb_3.text) +"'"
//MessageBox ( '标题',khmc)
//dw_1.setfilter(khmc)
end if
dw_1.setfilter(sffk+" and "+khmc)
dw_1.SetTransObject(sqlca)
dw_1.retrieve()
[解决办法]
我来给你写一段(也不一定就是最好):
dw_1.DataObject = "xiaoshouchaxun"
dw_1.visible = true
string ls_filter
//string sffk ,khmc,null_str//是否付款,客户名称
if ddlb_1.text <>"" then
ls_filter= "settleaccounts='" + string(ddlb_1.text) +"'"
end if
if ddlb_2.text <>"" and ddlb_3.text <>''then
if len(ls_filter)>0 then
ls_filter += " and client_clientname = '" + string(ddlb_3.text) +"'"
else
ls_filter = " client_clientname = '" + string(ddlb_3.text) +"'"
end if
end if
dw_1.setfilter(ls_filter)
dw_1.SetTransObject(sqlca)
dw_1.retrieve()