I am having a hard time understanding TQuery and the Prepare method.
I have created a simple application that consists of 1 form with:
a TButton named btnStart
a TEdit named edtNumEntries
a TQuery named qryGetInfo
DatabaseName = BCDEMOS
SQL = "SELECT * FROM Customer WHERE CustNo = :dbCustNo"
UniDirectional = true
I have a loop that calls the query over and over.
The query is prepared.
It seems that I have to call ->Close() to change the parameter value.
Does calling Close "Unprepare" the query?
If I call close, it runs slow but works.
If I don't call close, it runs fast but finds no data.
Can someone please shed some light on this?
What am I doing wrong (if anything)?
Note: If you run this, make sure to enter a number > 1200 to find some data.
This is the code I run when btnStart is clicked (please note this is C++Builder code but the idea is the same as in Delphi)
void __fastcall TfrmMain::btnStartClick(TObject *Sender)
TCursor Save_Cursor = Screen->Cursor;
Screen->Cursor = crHourGlass;
AnsiString strCompany = "";
TStringList *lstCompanies = new TStringList();
int NumEntries = StrToInt(edtNumEntries->Text);
for (int i = 0; i < NumEntries; i++)
qryGetSomeInfo->Close(); // <------ this is the line in question
qryGetSomeInfo->ParamByName("dbCustNo")->AsInteger = i;
strCompany = qryGetSomeInfo->FieldByName("Company")->AsString;
strCompany = "";
if (strCompany != "")
lstCompanies->Add(strCompany + " at " + IntToStr(i));
Screen->Cursor = Save_Cursor;