We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

Problem with simple ADOQuery

23 Views
Last Modified: 2020-12-16
I have a problem reading data from a query. the code below always throws an exception after assigning to v the Variant column from the result of the query ? the number of records found is 18. The query selects data on the basis of the column named 'Variant' so why does the Exception handler give the following message:

:0212288C L"ADOQuery1: Field 'Variant' not found"
I get the same error trying to get the values of any other columns in the result from the query.
I am using Embarcadero C++ Builder XE10.1 update 2 and the database is Microsoft SQL Server version 12.0.5223.6

void __fastcall TForm1::Button3Click(TObject *Sender)
{
 UnicodeString u,v;
 try
 {
  ADOQuery1->Close();
  ADOQuery1->Prepared = false;
  ADOQuery1->SQL->Clear();
  u.sprintf(L"Select * from Operations where Variant = 'VFLS3B2'");
  ADOQuery1->SQL->Add(u);
  ADOQuery1->Prepared = true;
  ADOQuery1->Open();
  if(ADOQuery1->RecordCount>0)
  {
   ADOQuery1->First();
   v = ADOQuery1->FieldByName(L"Variant")->AsString.Trim();
        }
 }
 catch(Exception &e)
 {
        u = e.Message;
  ADOQuery1->Close();
 }
}
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE