问题:在以下查询中为什么在dbgird1中不能得到查询的数据,而只显示域名呢??(要查询的数据已经存在查询表中) hbh:=trim(edit5.Text);
qfsj:=trim(edit6.Text);
ddsj:=trim(edit7.Text);
hkgs:=trim(combobox4.Text);
cfcs:=trim(combobox5.Text);
ddcs:=trim(combobox6.Text);
cwdj:=trim(combobox8.Text);
 adoquery3.close;if (length(hbh)<1) and (length(qfsj)<1) and (length(ddsj)<1)and(hkgs<>'请选择')and (cfcs='请选择') and (ddcs='请选择') and (cwdj='请选择') then
   showmessage('请输入查询信息!')
   else
   begin
  adoquery3.SQL.Clear;
  adoquery3.SQL.Add('select * from 查询表 where(航班号 like ''%' +hbh + '%'' and 出发城市 like ''%' + cfcs + '%'' and 到达城市 like ''%'+ ddcs +'%'' and 起飞时间 like ''%'+ qfsj + '%''and 到达时间 like ''%'+ ddsj +'%''and 舱位等级 like ''%'+cwdj+'%''and 航空公司 like ''%'+hkgs+'%'')');
  adoquery3.Open;
  adoquery3.Active:=true;
  datasource2.DataSet:=adoquery3;
  DBgrid1.DataSource:=datasource2;
  end ;
end;

解决方案 »

  1.   

    说明datasource2  和 adoquery3已拖放在窗体上, adoquery3.connectionstring已经连接
      

  2.   

    'select * from 表 where 航班号 like "%' + hbh + '%" and 出发城市 like "%' + cfcs + '%" and ……………………后面的都找这样改,好象是这样,我也没试,你试试要是不对再来的说
      

  3.   

    这样写,才能保证可以单项查询(比如只查航班号)
    with adoquery do
    begin
      Close;
      SQl.clear;
      sql.add(select * from kkkk where 1 = 1);
      if length(hbh) >=1 then
        sql.add('and 航班号 like ''' + '%' + hbh + '%' + '''');
      if (length(qfsj)>=1) then
         sql.add('and 出发城市 like ''' + '%' + qfsj + '%' + '''');
      if.............
       .............
      Open;
    end;