首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi怎么实现多条件模糊查询

2012-04-18 
delphi如何实现多条件模糊查询本人新手,麻烦各位大哥给解决下varstr:stringbeginstr:select * from box

delphi如何实现多条件模糊查询
本人新手,麻烦各位大哥给解决下
var
  str:string;
begin
  str:='select * from boxim where ';
  if Edit1.Text<>'' then
  begin
  str:=str+'瓶号 like ''%'+Trim(edit1.Text)+'%'' and ';
  end;
  if Edit2.Text<>'' then
  begin
  str:=str+'是否在库 like ''%'+Trim(edit2.Text)+'%'' and ';
  end;

  if Length(str)>0 then
  begin
  str:= LeftStr(str,Length(str)-5);

  Edit3.Text:=str;

  with DataModule2 do
  begin
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add(str);
  ADOConnection1.Connected:=True;
  ADOQuery1.Open;
  end;
  DBGrid1.DataSource.DataSet:=DataModule2.ADOQuery1;
  end;
end;

这是我网上看的LIKE的用法,我本来用ACCESS做的多条件模糊查询,现在想转DELPHI上,可不是这错就是那出错,麻烦各位大哥给改下
另外我想问下,现在DELPHI结合那种数据库开发最方便,多人共用的软件,要求数据同步更新

[解决办法]
str:='select * from boxim where 1=1 ';
if Edit1.Text<>'' then
begin
str:=str+' and [瓶号] like ''%'+Trim(edit1.Text)+'%''';
end;
if Edit2.Text<>'' then
begin
str:=str+'and [是否在库] like ''%'+Trim(edit2.Text)+'%''';
end;
[解决办法]
你好要保证如果你的edit中都没有值的情况不出错,你现在的不行,如果都没有值,就会成为
'select * from boxim where',不完整
[解决办法]
两个原则: where (1 = 1) ,再在后面跟条件代码,模糊查询写法自己注意一下,将'+QuotedStr('%'+text+'%')+ ',这样写就没有任何问题,主要是引号太多,你会比较迷惑
[解决办法]

探讨

两个原则: where (1 = 1) ,再在后面跟条件代码,模糊查询写法自己注意一下,将'+QuotedStr('%'+text+'%')+ ',这样写就没有任何问题,主要是引号太多,你会比较迷惑

热点排行