不如前面加checkbox来判断是否该字段和关键字组合是否生效生成几个变量或用数组如果 为true 就根据 字段值和关键字生成 查询语句然后查询时加上变量即可
参考一下
参考一下
解决方案 »
- Clientdataset 字段更新的问题
- 有个Edit,我想当我输完号码后按回车执行查询操作(新手,请多帮助)
- 关于视频系统是B/S好还是C/S版好
- 如何将Delphi应用程序注册成WindowsNT的服务呢?帮帮忙吧。
- 十万火急!高手帮忙看一下代码哪里有错误!分少请见谅~!
- 测试IP地址是否存在
- 为什么在windows 2000 server 上开发的.dpr文件(文件只要相对复杂一点)直接点击打不开?
- 请问在Windows2000/Xp下面编的程序怎么兼容windows98/ME???
- 请问怎样实现excel和数据库的互相关联的问题
- MapX中layer.selection怎么不完整呢?
- delphi组件问题
- 急!吐血大送分!怎样操作TADOQuery+Access2000中的备注字段?(80分相送,来者有份)
[email protected]下面代码也实现所要求的功能,但一大片的if语句看起来真不爽。
如果 tangyong_delphi() 有好方法请发到信箱,多谢 ,呵呵
procedure TmultiQueryForm.BitBtn1Click(Sender: TObject);
var
recordnum:integer;
strSql:string;
begin
recordnum:=0;strSql:='select * from info where true';strSql:=strSql+sqlcon; //调用sqlcon方法
//////
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add (strSql);
try
adoquery1.Open;
if not adoquery1.IsEmpty then
begin
recordnum:=adoquery1.RecordCount;
StatusBar1.Panels[0].Text :=' 共查询到 '+inttostr(recordnum)+' 条符合条件的记录!';
end
else
showmessage(' 对不起,没有查找到符合条件的记录! ');
except
showmessage('查询出现错误,xxxxxxxxxxxxxx');
end;end;
//////////////
function TmultiQueryForm.sqlcon: string;
var
strSql:string;
begin
strSql:='';
if editIsnull(trim(edit1.text)) then
strSql:=strSql+' and 姓名='+'"'+trim(edit1.text)+'"';
if editIsnull(trim(edit2.text)) then
strSql:=strSql+' and 用户号码='+'"'+trim(edit2.text)+'"';
if editIsnull(trim(edit3.text)) then
strSql:=strSql+' and 地址码='+'"'+trim(edit3.text)+'"';
if checkbox1.Checked then
strSql:=strSql+' and 启用日期 between '+'#'+datetostr(d1.date)+'#'+' and '+'#'+datetostr(d11.date)+'#';
if checkbox2.Checked then
strSql:=strSql+' and 结束日期 between '+'#'+datetostr(d2.date)+'#'+' and '+'#'+datetostr(d22.date)+'#';
if editIsnull(trim(combobox1.text)) then
strSql:=strSql+' and 入网方式='+'"'+trim(combobox1.text)+'"';
if editIsnull(trim(edit4.text)) then
strSql:=strSql+' and 机型='+'"'+trim(edit4.text)+'"';
if editIsnull(trim(combobox2.text)) then
strSql:=strSql+' and 类别='+trim(combobox2.text);
if editIsnull(trim(combobox3.text)) then
strSql:=strSql+' and 部门='+'"'+trim(combobox3.text)+'"';result:=strSql;end;