Procedure TfrmTest2. Btn1Click (Sender: TObject);
The begin
Adoquery1. Active:=False;
Adoquery1. SQL. The Clear;
Adoquery1. SQL. The Add (' select * from frmTest1 ');
Adoquery1. Active:=True;
The begin
If cbb1. Text='ascending' then
Adoquery1. You. Sort:='age asc'
The else
Adoquery1. You. Sort: 'age desc='
end;
end;
Where I went wrong, under the guidance of, want to have a headache,,,
CodePudding user response:
Online you brother taught me to know, online, etc.,,,CodePudding user response:
Procedure TfrmTest2. Btn1Click (Sender: TObject);
The begin
Adoquery1. Active:=False;
Adoquery1. SQL. The Clear;
Adoquery1. SQL. The Add (' select * from frmTest1 ');
Adoquery1. Active:=True;
the begin {visual here more than a begin}
If cbb1. Text='ascending' then
Adoquery1. You. Sort:='age asc'
The else
Adoquery1. You. Sort: 'age desc='
end {visual here more than an end}
end;
After the change:
Procedure TfrmTest2. Btn1Click (Sender: TObject);
The begin
Adoquery1. Active:=False;
Adoquery1. SQL. The Clear;
Adoquery1. SQL. The Add (' select * from frmTest1 ');
Adoquery1. Active:=True;
If cbb1. Text='ascending' then
Adoquery1. You. Sort:='age asc'
The else
Adoquery1. You. Sort: 'age desc='
end;
CodePudding user response:
//it is missing a semicolon;
Procedure TfrmTest2. Btn1Click (Sender: TObject);
The begin
Adoquery1. Active:=False;
Adoquery1. SQL. The Clear;
Adoquery1. SQL. The Add (' select * from frmTest1 ');
Adoquery1. Active:=True;
If cbb1. Text='ascending' then
Adoquery1. You. Sort:='age asc'
The else
Adoquery1. You. Sort:='age desc;
end;
CodePudding user response:
Well! Multiple end!Procedure TfrmTest2. Btn1Click (Sender: TObject);
The begin
With qry1 do begin
The close;
SQL. The clear;
SQL. The add (' select * from frmTest1 ');
The open;
If cbb1. Text='ascending' then
You. Sort:='age asc'
The else
You. Sort:='age desc;
end;
end;
CodePudding user response:
In this way, it is ok to:procedure TfrmTest2. Btn1Click (Sender: TObject);
Var: SQL string;
The begin
SQL:='select * from frmTest1';
If cbb1. Text='ascending'
Then SQL: SQL +='order by' ' 'age'
The else SQL: SQL +='order by' ' 'age' desc ';
Adoquery1. Active:=False;
Adoquery1. SQL. The Clear;
Adoquery1. SQL. The Add (SQL);
Adoquery1. Active:=True;
end;
CodePudding user response:
Adoquery1. SortDon't know why add in front of you
Sort attribute, don't need to manually refresh after a set
CodePudding user response:
Procedure TfrmTest2. Btn1Click (Sender: TObject);The begin
Adoquery1. Close;
Adoquery1. SQL. The Clear;
Adoquery1. SQL. The Add (' select * from frmTest1 ');
Adoquery1. Open;//usually try not to use the Active property, try using the Close and Open process
Case cbb1. Itemindex of//as far as possible use case, it is not easy to dazzle
ASC 0: adoquery1. Sort:='age;
1: adoquery1. Sort:='age DESC;
The else
Adoquery1. Sort:=' ';//reset
end;
end;