大约是这样:我有五个或更多的EDIT,如果五个都不为空的话就SELECT * FROM TABLE WHERE 条件1 LIKE EDIT1 AND 条件2 LIKE EDIT2......AND 条件5 LIKE EDIT5
如果只有EDIT2和EDIT3填了数据就SELECT * FROM TABLE WHERE 条件2 LIKE EDIT2 AND 条件3 LIKE EDIT3
意思是如果5个都不为空就有5个条件,只3个填EDIT的数据,就有3个条件,以此类推.
请问各位大侠,小弟应该如何判断和写代码呢?
小弟初学,请各位哥哥姐姐说详细点好吗?最好能有代码示范一下.谢谢了.
如果只有EDIT2和EDIT3填了数据就SELECT * FROM TABLE WHERE 条件2 LIKE EDIT2 AND 条件3 LIKE EDIT3
意思是如果5个都不为空就有5个条件,只3个填EDIT的数据,就有3个条件,以此类推.
请问各位大侠,小弟应该如何判断和写代码呢?
小弟初学,请各位哥哥姐姐说详细点好吗?最好能有代码示范一下.谢谢了.
解决方案 »
- 安装 Tee Chart
- 两个DBCombobox组合使用
- 写了一个ntservice的服务 不能启动外部程序 加急!!
- 双击DBGrid的滚动条会对数据源进行什么操作?
- 再发类似问题,四舍六入问题谁帮我修改一下程序
- SOS,各位大哥代码都写累了吧,近来换换脑筋看看我的问题!(制作电影)
- 如何修改dbgrid中输入的错误数据
- 一个关于软件加密的问题,制作钥匙盘的程序?急!
- 字符串操作,老生常谈的问题!!!!用POS和COPY解决不了的
- 关于sql server中存储过程的问题
- 如何建立数据库连接对象,
- 安装了DevExpress_ExpressQuantumGrid4.5的版本,在安装4.11的就不行了,怎么删除啊?
a1,a2:string;
sqlt,sqltemp:string;
begin
a1:=trim(edit1.text);
a2:=trim(edit2.text);
with adoquery1 do
begin
sqlt:='select * form 表名';
if length(a1)>0 then
sqltemp:='字段名 like ''%'+a1+'%''';
if length(a2)>0 then
sqltemp:=sqltemp+'字段名 like ''%'+a2+'%''';
if length(sqltemp)>0 then
begin
if uppercase(copy(TrimLeft(sqltemp),1,2))<>'WHERE' then
sqltemp:=' where '+sqltemp;
if trim(uppercase(copy(TrimRight(sqltemp),length(TrimRight(sqltemp))-3,length(TrimRight(sqltemp)))))='AND' then
sqltemp:=copy(TrimRight(sqltemp),1,length(TrimRight(sqltemp))-3);
end;
Close;
SQL.Clear;
SQL.Add(sqlt+sqltemp);
Open;
end;
end;
str := '';
if combobox2.Text <> '' then str := 'yhbh=''' + combobox2.text + '''';
if combobox3.Text <> '' then
if str <> '' then
str := str + ' and sbbh=''' + combobox3.text + ''''
else
str := str + ' sbbh=''' + combobox3.text + '''';
if edit3.Text <> '' then
if str <> '' then
str := str + ' and nd=''' + edit3.text + ''''
else
str := str + ' nd=''' + edit3.Text + '''';
if combobox1.Text <> '' then
if str <> '' then
str := str + ' and yf=''' + combobox1.Text + ''''
else
str := str + ' yf=''' + combobox1.Text + '''';
if RadioButton1.Checked = true then
begin
if str <> '' then
str := str + ' and sfycb =1'
else
str := str + ' sfycb =1';
end;
if RadioButton2.Checked = true then
begin
if str <> '' then
str := str + ' and sfycb =0'
else
str := str + ' sfycb =0';
end;
adoquery2.Filter := str;
adoquery2.Filtered := true;