I have a delphi form with TFDConnection, TFDQuery, TDataSource and TDBGrid. I want to show the data that my query gets (select * from table_1) and put it in my DBGrid. I've made all the connections between the components, but after I launch my query (which returns 12 rows) in my DBGrid are shown 12 rows but they are empty. Apparentely I forgot something that prevents me from seeing my data in my DBGrid. Can you help me what I'm missing in my actions ?
Can you try this:
Make your TFDQuery
active explicitly in your OnShow code of your Form. Like this,
procedure TForm.FormShow(Sender: TObject);
begin
FDQuery.Active:= True;
end;
It works for me and hope it helps.
To fix this problem (which I had the same), after you open the query, set:
datasource.dataset := Query
and the problem will be resolved.
You would get the behaviour that you would see the correct number of rows in the DBGrid, but the grid's cells are empty, if the DBGrid's DefaultDrawing
property is set to False
. if that's the case for your DBGrid, obviously just set DefaultDrawing
to True
.
I know the topic is old, but maybe it can help someone. In my case, the solution was: Deleting all the DBGrid columns that was created in design time, OR match the column's ( TColumn ) FieldName property to the EXACT field names as they named in the database tables.
For anyone else with this problem, here's the fix: make sure that the column names (not the Title) in the grid control match the field names in the query. Once they're matched they should behave properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.