Board index » delphi » FindNext after Post in a Query doesn't always work

FindNext after Post in a Query doesn't always work

Hi Folks

I've a problem with my Query component in Delphi 3. The following code
doesn't work, though I don't see why.

When I do Button3Click (see code snipped), not all of the records are
changed but only half of them. I have to click 4 times to change all
the records.

of course, I have    requestlive:=True

I would be very pleased to hear from someone who got the some
problems, or is there something wrong with my code.
If someone wants to test my example, the code is 3KB when zipped, I
will send it to you so you can test it.

----  part of code , needs Country.db from DBDEMOS ---

procedure TForm1.Button3Click(Sender: TObject);
begin
     Query1.Close;
     Query1.sql.clear;
     query1.sql.add('Select * from "Country.db"');
     query1.sql.add('Where Continent="South America"');
     query1.open;
     if Query1.findfirst=true then begin
        repeat
              Query1.edit;
              // an 'X' should be added to every ContinentName

Query1.FieldByName('Continent').AsString:=Query1.FieldByName('Continent').AsString
+'X';
              query1.post;
        until Query1.Findnext=False
     end;
end;

 

Re:FindNext after Post in a Query doesn't always work


Well, to change records withSQL you really ought to be using ExecSQL
rather than Open.

But if you want to do it this way then you should try:
    Query1.First;
    while not Query1.EoF do
        Query1.FieldByName('Continent').AsString:=Query1.FieldByName
            ('Continent').AsString + 'X';

Quote
Guy Besch wrote in message <35d1d0ad.9223...@sun.rhrk.uni-kl.de>...
>When I do Button3Click (see code snipped), not all of the records are
>changed but only half of them. I have to click 4 times to change all
>the records.

>procedure TForm1.Button3Click(Sender: TObject);
>begin
>     Query1.Close;
>     Query1.sql.clear;
>     query1.sql.add('Select * from "Country.db"');
>     query1.sql.add('Where Continent="South America"');
>     query1.open;
>     if Query1.findfirst=true then begin
>        repeat
>              Query1.edit;
>              // an 'X' should be added to every ContinentName

>Query1.FieldByName('Continent').AsString:=Query1.FieldByName('Contine
nt').AsString
>+'X';
>              query1.post;
>        until Query1.Findnext=False
>     end;
>end;

--
Stephen Brown
+44 (0)171 704 0702
sbr...@sprocket.win-uk.net

Other Threads