Delphi - Grid does not display all fields of the SQL statement

Asked

Viewed 799 times

0

I’ve been racking my brain for two days and I can’t figure out the problem. I have an SQL (Tfdquery) statement written in the code that selects three fields from a table to display them in a Dbgrid. I don’t know what happens. The third field is never shown. And if I retained one of the two fields that appear in the Dbgrid of the SQL statement, it gives error at runtime, saying that the field is missing.

The SQL statement is as below:

Note: Dataset is a Tfdquery. When I started using it, I wrote the instruction below directly in the SQL Command tab of the Query Editor component, but without the aluNascimento field. Then I started to write the instruction in the code for execution in Runtime and added the aluNascimento.

Formsearch.DataSet.SQL.Text := 'SELECT idAluno, aluNome, aluNascimento FROM Students WHERE aluNome LIKE :Name';

The aluNascimento field does not appear in Dbgrid. And if I remove the idAluno or aluNome field from the SQL statement, the runtime error arises saying that the field is missing.

Someone’s been through something similar ?

Thanks for any help.

  • Good morning, see in the DFM of your form where is the dataset if there is any persistent reference of Fields (in dataset or grid). To see the DFM press Alt + F12.

  • Hello Andrey. Thank you for your reply. In Datamodule DFM is as below:

  • Good morning, Andrey. YOU ARE RIGHT !!!. I opened the DFM of the Datamodule and there were constanting the two fields. Deletes the Tfdquery from the Datamodule, saved and put another Tfdquery component with the same "name". I checked the application and worked well, including already showing the third field. Thank you very much. Great hug.

2 answers

0

There are several possibilities for the field not to appear. Among them: 1) The field object is invisible, 2) The dataset has field objects, but not that field specifically (Fields editor), 3) dbgrid has column objects, but not the column of that specific field.

  • Hi Ricardo. 1) I am not leaving any invisible Column; 2) I am not using Fields Editor because the amount of fields can change; and 3) Dbgrid has no column defined through Columns Editor (the amount of columns appears according to the amount of SQL fields). The strange thing is that the first two columns appear. Does SQL get saved somewhere ? Since when I remove an SQL field defined in the code it gives error saying that field is missing...

  • One more possibility: see the Dataset Fielddefs property. If you have objects you can clear everything. If I’m not mistaken, fields are included there when Storedefs = True.

  • Hello Ricardo. Andrey has located the problem as above. Thank you very much for your help.

0


Good morning, as commented above, it is possible that there are Fields persistent in the dataset.. one way to check is to check in the DFM of your form (where is the dataset) whether there is any persistent reference to Fields (in the dataset or on the grid).
To see the DFM press the button Alt + F12.
If the Fields persistent are found, just remove them (preferably by normal means, finding the Fields visually).

  • Hi Andrey. As commented above, you killed the riddle and I already fixed the problem. Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.