• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

C++ Builder5: problem with query

I run this piece of code:

QR->Close();
QR->SQL->Clear();
QR->SQL->Add("SELECT somefields FROM sometable");
QR->Open();

and QR->open throws a mysterious exception: "QR: Field OTHERFIELD not found". Its mysterius, because OTHERFIELD is not presend in 'somefields'...

Any ideas how should I solve this?
0
Robson
Asked:
Robson
  • 3
  • 3
1 Solution
 
RobsonAuthor Commented:
Additional info: table 'sometable' contains field 'OTHERFIELD'.
0
 
BoomersCommented:
Hi Robson,

His QR an object TQuery on your Form or did you code it with the TQuery *QR;
If it is on a form. Make sure that when you dbl-click on the object to look at the field, you do not see the field OTHERFIELD.

Your field on your SQL query and your field on your object should be the same.

Hope this helps!!!
0
 
RobsonAuthor Commented:
Hmm, just how you suspected: the query is included on the form with all fields from sometable. Maybe there is a way to temporary disable them? QR->DisableControls don't work....
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
BoomersCommented:
Hi Robson,

    I don't think you can disable theses TField but i'll look at it. You could delete all the field from the TQuery object and change your reference to theses field using the following syntax:

String a;
a = QR->FieldByName("Field1")->AsString;

This way the TTable will only contains the field that are within your SQL statement. The only thing is that no TField will be accessible since they are based on a SQL Statement that is created at run time.

Let me know if this helps!!!
0
 
DrDelphiCommented:
You can change the Required property of the field in question, either in code or through the Object Inspector. If you're using using a TQuery, you might as well just delete all the fields, anyway. You can always just include them in your SQL statements... Food for thought.


Good luck!!
0
 
RobsonAuthor Commented:
Points go to Boomers who firs diagnosed my problem.

Thanks for your Comment, DrDelphi. I checked Required property and for all fields it's set to false :-( It confused me even more, but I haven't created this form and I'm not going to redesign it.
0
 
BoomersCommented:
Thanks for the A grade Robson.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now