Hi all, it's me again... sorry...
DataModule1.SQLQuery1.First;
while not DataModule1.SQLQuery1.EOL do begin
// example code, not tested much, only ~25 years :o)
if DataModule1.SQLQuery1.FieldByName('Surname').AsString = Searchkey then
break; // out of the loop and leaves sqlquery at that record...
DataModule1.SQLQuery1.Next; //<- very important!
end;
You wrote that "break" get out of the loop and leaves sqlquery at that record...
But I placed in my form an UpDown intended to access the next or previous record, and, in fact, when I click on Up or Down I see that the dataset is not on the record found by the test on the key
Voici mon code:
First, the first search on the dataset
if Ok=true then
begin
if (KeySearch.Text<>'') then
begin
DataModule1.SQLQuery1.First;
while not DataModule1.SQLQuery1.EOF do
begin
if copy(DataModule1.SQLQuery1.FieldByName('IDLUGES').AsString,4,7)=KeySearch.Text then
break;
DataModule1.SQLQuery1.Next;
end;
end;
ShowRecord();
end;
(ShowRecord is a procedure which put fields contents in Edits)
Then the procedure when clicking on UpDown
procedure TFormSaisMvtEmp.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
case Button of
btPrev:
begin
DataModule1.SQLQuery1.Prior;
if copy(DataModule1.SQLQuery1.FieldByName('IDLUGES').AsString,4,7)=KeySearch.Text then
ShowRecord();
end;
btNext:
begin
DataModule1.SQLQuery1.Next;
if copy(DataModule1.SQLQuery1.FieldByName('IDLUGES').AsString,4,7)=KeySearch.Text then
ShowRecord();
end;
end;
end;
(I know a "while" would be needed, but it's just a attempt here)
Maybe I would be better off putting a filter corresponding to the search key on the dataset from the start, but I haven't found an example and I don't see what mistake is mine.
Thanks !