Reputation: 484
Problem background: So I'm trying to display a table (the specific table gets selected in a radio group in my GUI) from my database normally in a DBGrid so that when a user types in a SQL query they would be able to see the changes in the table in the DBGrid. (All images shown are from Delphi's design view unless otherwise stated)
Image of radio group where you can select a table (the radio group doesn't do anything yet):
The main problem: The problem is it doesn't display everything, it only displays the first column on the DBGrid and nothing else.
Example of the output I'm talking about:
Extra info regarding the form, components, etc: The data source connected to my DBGrid declared as a TDataSource component is called dsrSQL. I'm using a TADOQuery component called qrySQL which is connected to conClientInfo (a TADOConnection component that connects to the database). That data source has qrySQL as it's DataSet. All of the components are active and enabled. They are also all in one single data module called DM_client_u. (I did declare the data module under uses in my form's code)
Image of one of the tables in Access:
What I tried: I redid the connection string in conClientInfo, checked the qrySQL component and the DBGrid. I still don't see any problems on the surface of the program.
Thanks in advance!
Upvotes: 1
Views: 1337
Reputation: 30715
If you don't mind me saying so, you are creating problems for yourself by trying to use the same DBGrid to display data from 2 tables with different structures, when you don't know how to do it. In any case, trying to do it means you lose the ability to set up the grid's appearance at design time and adapt it to suit the particular data from each table.
Here's what I suggest you do instead:
Add a TPageControl to your form and add two TTabSheets to it.
Put a TDataSource, TDBGrid and TDBNavigator on each TTabSheet, and connect each TDataSource to one of the datasets in your datamodule. Assuming the AdoQueries involved already have Sql suited to retrieve the data you wish to display, set both AdoQueries to active and use the Columns editor (which you can access by right-clicking each TDBGrid) to set up and size the grid Columns for each field.
Now you can control the display of each AdoQuery independently without tying yoursself in knots.
If using a TPageControl is not to your taste, do something like embedding each TDBGrid it its own TPanel, make the two TPanels occupy the exact same area on your form and use code to display one of the panels or the other depending on the setting of your TRadioGroup, by setting one TPanel's Visible property to True and the other to False.
Btw, once you've got the 2 TDBGrids looking and working as you want, set the AdoQueries to Active = False and use code to open them at run-time - it's bad practice to leave things like DB connections and DataSets active at design time. You'll find out why when you get an unexpected problem, e.g. when you are expecting your app to have exclusive access to the tables, as when attempting to restructure them ar run-time.
Upvotes: 2