Board index » delphi » Strange behavior of a Query: Could not find record

Strange behavior of a Query: Could not find record

Hello I have a strange problem, this is my code, I create a simple
query, then I go tthrough every record of the query, then I call
First() and go again through it.
I used those Memo1->Lines to check the flow of the program. Everything
works.
When I cancel the Memo1->Lines->Add() I get a "Could not find record"
at the second Next().
It must be a sort of timing, Query is not ready, or something like
that,but how can I prevent the "Could not find record?"

Thank you!

DMod->QryUominiCGiornalieriUnf2->Close();
DMod->QryUominiCGiornalieriUnf2->SQL->Strings[1]="WHERE (IDUomo
="+(AnsiString)Uomo+") AND
(Date='"+Date.FormatString("yyyy'/'mm'/'dd")+"')";

Memo1->Lines->Add("Test "+ Data.FormatString("yyyy'/'mm'/'dd"));

 DMod->QryUominiCGiornalieriUnf2->Open();

 while (!DMod->QryUominiCGiornalieriUnf2->Eof) {

OreGiorno+=DMod->QryUominiCGiornalieriUnf2->FieldByName("Ore")->AsFloat;
                            DMod->QryUominiCGiornalieriUnf2->Next();
                            }
 DMod->QryUominiCGiornalieriUnf2->First();
 while (!DMod->QryUominiCGiornalieriUnf2->Eof) {
                            DMod->QryUominiCGiornalieriUnf2->Edit();

DMod->QryUominiCGiornalieriUnf2->FieldByName("Used")->AsBoolean=true;

DMod->QryUominiCGiornalieriUnf2->FieldByName("OreGiorno")->AsFloat=OreGiorno;

Memo1->Lines->Add("QryUominiCGiornalieriUnf2 filter
Data"+Data.DateString()+"      Uomo  "+(AnsiString)Uomo);
Memo1->Lines->Add("OK4");
                            DMod->QryUominiCGiornalieriUnf2->Next();
Memo1->Lines->Add("OK
"+DMod->QryUominiCGiornalieriUnf2->FieldByName("ID")->AsString+"
"+DMod->QryUominiCGiornalieriUnf2->FieldByName("IDUomo")->AsString);
                            }
                        }
Memo1->Lines->Add("OK5");

 

Re:Strange behavior of a Query: Could not find record


Make sure you have a primary key. After you do a post, do a refresh and
reposition (for a query you have to close and open).

Note: Please do not crosspost. Select the single most appropriate group
for your question.

------
Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------

Re:Strange behavior of a Query: Could not find record


Quote
>Make sure you have a primary key. After you do a post, do a refresh and
>reposition (for a query you have to close and open).

What's the correct way to reposition after a close/open?
thanks

Quote
>Note: Please do not crosspost. Select the single most appropriate group
>for your question.

I know, I'm a CBuilder programmer, but Delphi and CBuilder for most
things are almost the same, expecially database, and I get much more
answers in the Delphi group than in the CBuilder one.

Other Threads