strsql:='select * from table1 where ';
if (edit1.text<>''then strsql:=strsql+' d1='+edit1.text+'AND';
if (edit.text<>''then strsql:=strsql+'d1='+edit1.text+'AND d2='+edit2.text+'AND';
if <> then strsql:=strsql+'d1='+edit1.text+'AND';
...
strsql:=copy(strsql,1,length(strsql)-3);
if (edit1.text<>''then strsql:=strsql+' d1='+edit1.text+'AND';
if (edit.text<>''then strsql:=strsql+'d1='+edit1.text+'AND d2='+edit2.text+'AND';
if <> then strsql:=strsql+'d1='+edit1.text+'AND';
...
strsql:=copy(strsql,1,length(strsql)-3);
解决方案 »
- 将Windows桌面分成几个区域,实现比如控制最大最小化区域设定。
- 如何保留文件大小中的小数点
- 怎样写一个dll,让别人调用后能写远程的数据库
- 如何得到RichEdit的真正大小
- 这个异常该怎么解决?
- 利用GotoKey查询到结果后,如何将结果返回到另外一个窗口的DBGrid中?
- 请问:如何在集成有声卡的主板上成功安装ISA声卡呀
- 这段代码什么意思?
- 敬请各位网络高手解疑,一个困扰我的网络传输问题?
- 菜鸟问题5:delphi中有没有弹出对话框,要你选择是,否,取消,然后得到返回值,实在很抱歉,我是刚学delphi的新手,很多都不懂
- 怎样获取ShellTreeView1的文件夹名(含路径)?
- QQ收费后你会怎么办?
1,记录与查询条件一多,慢死了
2,一旦出现所有的edit都为空,where就是多余的
抱歉,好的我还没想到
var
dateOk,keyOk,vipOk :Boolean ;//判断是否用日期、关键字进行过滤
begin
dateOk :=(dateGroupBox.font.Color =clGreen);
keyOk :=(keyGroupBox.font.Color =clGreen);
vipOk :=vipCheckBox.Checked ; with diaryAdoQuery do begin
close;
sql.clear;
sql.add('select * from ');
sql.add(iTableName);
sql.add(' where 名称=:名称');
if dateOk then sql.add(' and 日期 between :startDate and :stopDate');
if vipOk then sql.add(' and ok =:ok');
if keyOk then sql.add(' and 内容 like ''%'+keyEdit.text+'%''');
if dateOk then begin
parameters.paramByName('startDate').value :=startDateTimePicker.DateTime ;
parameters.paramByName('stopDate').value :=stopDateTimePicker.DateTime ;
end;
if vipOk then
parameters.paramByName('ok').value :=true ;
parameters.paramByName('名称').value :=iCaption;
open;
Last ;
end;
queryBitBtn.Enabled :=false;
noQueryBitBtn.Enabled :=true;
end;
with Form1 do
begin
for i:=0 to ControlCount-1 do
begin
if (Controls[i] is TComboBox) then
if (Controls[i] as TComboBox).Text<>'' then
begin
if get<>'' then
get:=get+' and ';
get:=get+(Controls[i] as TComboBox).Name+'='''+(Controls[i] as TComboBox).Text+'''';
end;
if (Controls[i] is TEdit) then
if (Controls[i] as TEdit).Text<>'' then
begin
if get<>'' then get:=get+' and ';
if isNumber((Controls[i] as TEdit).Text) then
get:=get+(Controls[i] as TEdit).Name+'='+(Controls[i] as TEdit).Text
else
get:=get+(Controls[i] as TEdit).Name+'='''+(Controls[i] as TEdit).Text+'''';
end;
end;
end;
if get<>'' then
strsql:='select * from table1 where '+get
else
strsql:='select * from table1';
如果是combobox(style=DropDownList),直接传递参数!
试试吧