请各位高手帮我纠正源代码,怎么不能实现综合查询?

lusui666 2003-07-27 10:09:42
各位高手,我在PB8里面用三个复选框做的一个综合查询,可是只能实现单个查询,当两个及以上组合的时候,却不能检索出关键词,错在哪里?源代码如下:

string ls_temp1,ls_temp2,ls_temp3
string ls_filter,ls_filter1,ls_filter2,ls_filter3
if cbx_1.checked =true then
ls_temp1=trim(sle_1.text)
ls_filter1=''
if pos(ls_temp1,'',1) > 0 then
ls_filter1=ls_filter1+"gjc like'"+trim(left(ls_temp1,pos(ls_temp1,'',1)))+"'and"
ls_temp1=replace(ls_temp1,1,pos(ls_temp1,'',1),'')
else
ls_filter1="gjc like'"+ls_temp1+"'"
ls_temp1=''
end if
end if
if cbx_2.checked =true then
ls_temp2=trim(sle_2.text)
ls_filter2=''
if pos(ls_temp2,'',1) > 0 then
ls_filter2=ls_filter2+"gj like'"+trim(left(ls_temp2,pos(ls_temp2,'',1)))+"'and"
ls_temp2=replace(ls_temp2,1,pos(ls_temp2,'',1),'')
else
ls_filter2="gj like'"+ls_temp2+"'"
ls_temp2=''
end if
end if
if cbx_3.checked =true then
ls_temp3=trim(sle_3.text)
ls_filter3=''
if pos(ls_temp1,'',1) > 0 then
ls_filter3=ls_filter3+"cbrq like'"+trim(left(ls_temp3,pos(ls_temp3,'',1)))+"'and"
ls_temp3=replace(ls_temp3,1,pos(ls_temp3,'',1),'')
else
ls_filter3="cbrq like'"+ls_temp3+"'"
ls_temp3=''
end if
end if
if cbx_1.checked=true then
if cbx_2.checked=false and cbx_3.checked=false then
ls_filter=ls_filter1
end if
elseif cbx_2.checked=true then
if cbx_1.checked=false and cbx_3.checked=false then
ls_filter=ls_filter2
end if
elseif cbx_3.checked=true then
if cbx_1.checked=false and cbx_2.checked=false then
ls_filter=ls_filter3
end if
elseif cbx_1.checked=true and cbx_2.checked=true then
if cbx_3.checked=false then
ls_filter=""+ls_filter1+""+"and"+" "+ls_filter2+""
end if
elseif cbx_1.checked=true and cbx_3.checked=true then
if cbx_2.checked=false then
ls_filter=""+ls_filter1+""+"and"+" "+ls_filter3+""
end if
elseif cbx_2.checked=true and cbx_3.checked=true then
if cbx_1.checked=false then
ls_filter=""+ls_filter2+""+"and"+" "+ls_filter3+""
end if
else
ls_filter=""+ls_filter1+""+"and"+" "+ls_filter2+""+"and"+" "+ls_filter3+""
end if
//过滤输出
dw_1.setfilter(ls_filter)
dw_1.filter()
//检索显示
dw_1.SetTransObject(sqlca)
dw_1.retrieve()
if dw_1.rowcount()=0 then
messagebox("系统提示:","对不起,数据库中无记录!")
return
end if
...全文
25 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zunyir 2003-08-12
  • 打赏
  • 举报
回复
是两个"中差一个'号!
不是"",应该是"'"
klbt 2003-07-30
  • 打赏
  • 举报
回复
你最后的ls_filter,计算结果是什么?
eminena 2003-07-30
  • 打赏
  • 举报
回复
在窗口放置 Sle_1

代码中;parent.sle_1.text=ls_filter
查看
dotnba 2003-07-29
  • 打赏
  • 举报
回复
将生成的语句显示出来,看看就知道原因了
lusui666 2003-07-29
  • 打赏
  • 举报
回复
可是,当我去掉“and"的时候,还是不行啊,设置断点,调试程序,还是没有什么结果,怎么办呢?
lusui666 2003-07-28
  • 打赏
  • 举报
回复
谢谢您,我试一下再给您打分。
godofn 2003-07-28
  • 打赏
  • 举报
回复
你的ls_filter变量开始就加了and关键字,在后面的综合查询里面你又添加了and ,好象也是不对的。
klbt 2003-07-27
  • 打赏
  • 举报
回复
你的and、like两边要加上空格!
你跟踪一下ls_filter的最后数值,就明白了。

752

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧