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什么的不一样呢?
[解决办法]
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;