读书人

adoquery 多条件查询?解决方案

发布时间: 2012-02-17 17:50:42 作者: rapoo

adoquery 多条件查询?
procedure TForm1.Button4Click(Sender: TObject);

begin
adoquery2.SQL.Clear;
adoquery2.Close;
adoquery2.sql.Text:=('select * from 表 where 字段1=:V or 字段2 =:v');
adoquery2.parameters.parambyname('V').value :=edit3.Text;
adoquery2.Open;
end;

end.


只有字段1起作用
写法是不是和VB什么的不一样呢?


[解决办法]

Delphi(Pascal) code
procedure TForm1.Button4Click(Sender: TObject); beginadoquery2.Close; adoquery2.SQL.Clear; adoquery2.sql.add( 'select * from 表 where 字段1=:V or 字段2 =:v '); adoquery2.parameters.parambyname( 'V ').value :=edit3.Text; adoquery2.Open; end;end.
[解决办法]
加个括号吧
procedure TForm1.Button4Click(Sender: TObject);
begin
adoquery2.SQL.Clear;
adoquery2.Close;
adoquery2.sql.Text:=( 'select * from 表 where (字段1=:V) or (字段2 =:v) ');
adoquery2.parameters.parambyname( 'V ').value :=edit3.Text;
adoquery2.Open;
end;

读书人网 >.NET

热点推荐