I’m building an app in CppBB6 that reads/writes data from/in a database. From a table called Students I want to extract the Name of a student using the given Index number (both Name and Index are fields in table Student) and afterwards I want to put that Name in a String or AnsiString variable.
I’m using this query to select the name:
AnsiString query;
Query1->Close();
Query1->UnPrepare();
Query1->SQL->Clear();
query="SELECT Name FROM Students where Index='" + Edit1->Text + "'";
Query1->SQL->Add(query);
Query1->Prepare();
Query1->Open();
and it all checks out fine, but how do I put that Name in a variable? :/
I’d guess something like
or in case you really only have one field and/or know index of the field(s) then
And as Ken White suggest in comments – one should really use parameterized queries for safety and perfomance reasons, something like