f trim(combobox1.Text)<>'' then
fil:='类别 like %'+trim(combobox1.Text)+'%';if trim(combobox2.Text)<>'' then
if fil='' then
fil:='名称 like %'+trim(combobox2.Text)+'%'
else
fil:=fil+' and 名称 like %'+trim(combobox2.Text)+'%';if trim(combobox3.Text)<>'' then
if fil='' then
fil:='规格 like %'+trim(combobox3.Text)+'%'
else
fil:=fil+' and 规格 like %'+trim(combobox3.Text)+'%';if trim(combobox4.Text)<>'' then
if fil='' then
fil:='品牌 like %'+trim(combobox4.Text)+'%'
else
fil:=fil+' and 品牌 like %'+trim(combobox4.Text)+'%';////////////////////////以下的有问题////////////////
if trim(combobox5.Text)<>'' then
if fil='' then
fil:='车型 like %'+trim(combobox5.Text)+'%'+' or 通用车型 like %'+trim(combobox5.Text)+'%'
else
fil:=fil+' and ( 车型 like %'+trim(combobox5.Text)+'%'+' or 通用车型 like %'+trim(combobox5.Text)+'% )';//////////////////////////////////////////////////////
with adotable2 do
begin
filtered:=false;
filter:=fil;
filtered:=true;====================================
数据库:Access
功能:通过comboxbox组件的输入来过滤ADOTable2。
说明:combobox5中的内容对应“车型”字段和“通用车型”字段。即combobox5.text既可以是“车型”,也可以是“通用车型”。出现问题:如果combobox1至4不输入内容的话,那么fil='车型 like %'+trim(combobox5.Text)+'%'+' or 通用车型 like %'+trim(combobox5.Text)+'%',此时运行不会出错。
但只要combobox1至4任何一个输入了内容的话,同时combobox5也输入了的话,
那么fil=fil+' and ( 车型 like %'+trim(combobox5.Text)+'%'+' or 通用车型 like %'+trim(combobox5.Text)+'% )';此时出现参数类型错误的提示。
我用括号括住"车型 like %'+trim(combobox5.Text)+'%'+' or 通用车型 like %'+trim(combobox5.Text)+'% '"是想只要combobox5.text附合“车型”字段或“通用车型”字段就成立。以上有什么错误呢?怎样解决?

解决方案 »

  1.   

    假如把以下的去掉,过滤是没问题的。
    ////////////////////////以下的有问题////////////////
    if trim(combobox5.Text)<>'' then
    if fil='' then
    fil:='车型 like %'+trim(combobox5.Text)+'%'+' or 通用车型 like %'+trim(combobox5.Text)+'%'
    else
    fil:=fil+' and ( 车型 like %'+trim(combobox5.Text)+'%'+' or 通用车型 like %'+trim(combobox5.Text)+'% )';//////////////////////////////////////////////////////
      

  2.   

    用Filter屬性很不穩定!為不直接用sql語句直接寫呢?