delphi 中如何用 sql语句中like实现复选框的查询功能(模糊)
用CHECKBOX这个控件怎么写程序呢?按以下代码写的程序出现的问题是:只要是查询项,无论选没选,在数据库中是空的记录都查不出来。谢谢!procedureTForm19....
用CHECKBOX这个控件怎么写程序呢?按以下代码写的程序出现的问题是:
只要是查询项,无论选没选,在数据库中是空的记录都查不出来。谢谢!
procedure TForm19.Button3Click(Sender: TObject);
var YBXH,WH,YBMC,QH,CDMC,......:string;
begin
YBXH:='%';WH:='%';QH:='%';CDMC:='%';TUNIT:='%';YBMC:='%';
......
if CheckBox1.Checked=true then YBXH:=edit3.Text;
if CheckBox2.Checked=true then WH:=edit27.Text;
if CheckBox3.Checked=true then YBMC:=wwDBLookupCombo5.text;
......
WITH wwQuery1 DO
begin
close;
sql.clear;
sql.Add('select * from ybtz');
sql.add('where YBXH like :YBXH and WH like :WH and YBMC like :YBMC and QH like :QH ');
sql.add(' and GGLC like :GGLC and LB like :LB and GLZT like :GLZT and CDMC like :CDMC and UNIT like :TUNIT and SX like :SX');
sql.Add('order by WH,YBMC');
paramByName('YBXH').asstring:='%'+YBXH+'%';
paramByName('WH').asstring:='%'+WH+'%';
......
open;
end; 展开
只要是查询项,无论选没选,在数据库中是空的记录都查不出来。谢谢!
procedure TForm19.Button3Click(Sender: TObject);
var YBXH,WH,YBMC,QH,CDMC,......:string;
begin
YBXH:='%';WH:='%';QH:='%';CDMC:='%';TUNIT:='%';YBMC:='%';
......
if CheckBox1.Checked=true then YBXH:=edit3.Text;
if CheckBox2.Checked=true then WH:=edit27.Text;
if CheckBox3.Checked=true then YBMC:=wwDBLookupCombo5.text;
......
WITH wwQuery1 DO
begin
close;
sql.clear;
sql.Add('select * from ybtz');
sql.add('where YBXH like :YBXH and WH like :WH and YBMC like :YBMC and QH like :QH ');
sql.add(' and GGLC like :GGLC and LB like :LB and GLZT like :GLZT and CDMC like :CDMC and UNIT like :TUNIT and SX like :SX');
sql.Add('order by WH,YBMC');
paramByName('YBXH').asstring:='%'+YBXH+'%';
paramByName('WH').asstring:='%'+WH+'%';
......
open;
end; 展开
4个回答
展开全部
sql.add(' and GGLC like :GGLC and LB like :LB and GLZT like :GLZT and CDMC like :CDMC and UNIT like :TUNIT and SX like :SX');
改为
sql.add(' and isnull(GGLC,"") like :GGLC and isnull(LB,"") like :LB and isnull(GLZT,"") like :GLZT and isnull(CDMC,"") like :CDMC and isnull(UNIT,"") like :TUNIT and isnull(SX,"") like :SX');
改为
sql.add(' and isnull(GGLC,"") like :GGLC and isnull(LB,"") like :LB and isnull(GLZT,"") like :GLZT and isnull(CDMC,"") like :CDMC and isnull(UNIT,"") like :TUNIT and isnull(SX,"") like :SX');
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
procedure TForm19.Button3Click(Sender: TObject);
var YBXH,WH,YBMC,QH,CDMC,......:string;
begin
YBXH:='%';WH:='%';QH:='%';CDMC:='%';TUNIT:='%';YBMC:='%';
......
if CheckBox1.Checked=true then YBXH:=YBXH+trim(edit3.Text);
if CheckBox2.Checked=true then WH:=WH+trim(edit27.Text);
if CheckBox3.Checked=true then YBMC:=YBMC+trim(wwDBLookupCombo5.text);
......
WITH wwQuery1 DO
begin
close;
sql.clear;
sql.Add('select * from ybtz ');
sql.add('where YBXH like :YBXH and WH like :WH and YBMC like :YBMC and QH like :QH ');
sql.add(' and GGLC like :GGLC and LB like :LB and GLZT like :GLZT and CDMC like :CDMC and UNIT like :TUNIT and SX like :SX');
sql.Add('order by WH,YBMC');
paramByName('YBXH').asstring:=YBXH+'%';
paramByName('WH').asstring:=WH+'%';
......
open;
end;
var YBXH,WH,YBMC,QH,CDMC,......:string;
begin
YBXH:='%';WH:='%';QH:='%';CDMC:='%';TUNIT:='%';YBMC:='%';
......
if CheckBox1.Checked=true then YBXH:=YBXH+trim(edit3.Text);
if CheckBox2.Checked=true then WH:=WH+trim(edit27.Text);
if CheckBox3.Checked=true then YBMC:=YBMC+trim(wwDBLookupCombo5.text);
......
WITH wwQuery1 DO
begin
close;
sql.clear;
sql.Add('select * from ybtz ');
sql.add('where YBXH like :YBXH and WH like :WH and YBMC like :YBMC and QH like :QH ');
sql.add(' and GGLC like :GGLC and LB like :LB and GLZT like :GLZT and CDMC like :CDMC and UNIT like :TUNIT and SX like :SX');
sql.Add('order by WH,YBMC');
paramByName('YBXH').asstring:=YBXH+'%';
paramByName('WH').asstring:=WH+'%';
......
open;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
procedure TForm1.Button1Click(Sender: TObject);
begin
case RadioGroup1.ItemIndex of
0:
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 表 where 字段 like '+''''+trim(edit1.Text)+'''');
end;
1: //同理
end;
end;
begin
case RadioGroup1.ItemIndex of
0:
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 表 where 字段 like '+''''+trim(edit1.Text)+'''');
end;
1: //同理
end;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 表 where 字段 like %'+edit1.text+'%');
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 表 where 字段 like %'+edit1.text+'%');
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询