I am facing a very strange problem in one of my programs. I have a TSQLConnection followed by two TSQLQUery, TDataSetProvider, TClientDataSet and TDataSource. Its a Master-Detail structure.
The TDataSource of the detail query has an additional column with one lookup property of the master query. (Think of something like 'ProductID, ProductName, GroupName' where GroupName comes from the master query)
Then I have a DBGrid which has the TDataSource of the detail query as Source. It diplays most parts correctly, but the field that is a lookup from the master-query, sometimes does not show. Sometimes means in this case, i scroll down in the DBGrid, and up again, then its gone. I scroll down and up one more time, and its shown.
For debugging I added a TDBLookupComboBox with the same source as the DBGrid, but the ComboBox always shows the correct value for this field.
Thanks for any help on this problem.
Try changing the LookupCash property of the lookup column to true, I think this will solve the problem.
Related
I use Delphi 10.2 with ComponentAce's Absolute Database framework. So my question here can pertain to TAbsQuery or, I presume, the conventional Delphi TQuery class.
My database has a date field named lastViewed. I have the RequestLive set to true so that any changes made to various fields in the current record are persisted to the table. Additionally, in my BeforeScroll event (i.e., prior to advancing to another record) the lastViewed field is updated to the current date. It works just fine. However, I have a menu option that displays a list of all records sorted by the last viewed date. In other words,
SELECT * FROM myTable ORDER BY lastViewed
It looks just fine when the results are initially shown in the DBGrid (TAbsGrid, in my case). But as I scroll down the list, the lastViewed field is updated and that record is pushed to the bottom of the grid. I would like the original order of the list to be preserved as I scroll up or down the list.
Turning LiveRequest to false will obviously trigger a database error when updating the DB fields in my BeforeScroll event.
The same issue would occur if, say, I want to show results for all records having the myFavoriteColor field with a RED value. Changing the myFavoriteColor value to GREEN, that row would disappear from my query results list.
Is there a way to keep the current query results in tact, while still being able to update the underlying table with new data?
Thank you for reading this.
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 ?
1- Adding all components to the form.
2- Connect FDQuery with FDConnection, TDataSource with FDQuery, DBGrid with TDataSource.
3- Connection parameters succed in testing (the problem is not in my connection parameters)
4- The number of rows are placed in my DBGrid (12), but with no information visible.
5- If I loop through my FDQuery I can see all the information I need but that doesn't help me populate my DBGrid.
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.
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.
To fix this problem (which I had the same), after you open the query, set:
datasource.dataset := Query
and the problem will be resolved.
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.
I'm new to delphi and have created an SQL query which displays the results of a search entered by the user through an edit box (showing data from 2 related tables) in a dbGrid.
The dbgrid displays no data until a search has been made and then the results of that search are displayed, however i was wondering whether it was possible to show all the related data in the dbgrid as if it were a table and the search then simply selects from it?
thanks
You could display all the data in the table. Then write an onExit event handler for your edit box which would look something like this (assuming that the string which you are entering in the edit box is supposed to match the value in the 'name' field of the query)
query.locate ('name', edit1.text, [loPartialValue]);
This will cause the dbgrid's cursor to jump to the first line which matches the string in the edit box.
Instead of using the OnExit event, you could also use the OnChange event of the edit box, but this would mean a search after every key stroke.
Your question was a bit vague so it's difficult to give a specific answer.
A bit of History:
I have a DBlistbox containing textt descriptions and I store just the codes of this in a mysql table which is displayed in a dbgrid. User can select multiple options and I like to process these and store as comma separated values in one of the columns (this column is invisible in the dbgrid).
Right now I can populate the listbox when the user scroll through the dbgrid using event Afterscroll and Formcreate. But when I try to process the list and update the myquery behind the dbrgid I get an error saying 'Dataset not in Edit or Insert mode' - I do this in beforescroll
Please help!!
I have tried to set the dataset to edit mode before changing then as soon the data is posted dbgrid seems to have funny characters
If I got you right, the DBListBox is not connected to the dataset lonked in the grid? This would explain why the grid's dataset is not set to edit mode when you change the data in the DBListBox.
Anyway, whenever you change data that has to go into the mysql table, you should switch this dataset into edit mode. Then you can place your coding of the comma separated values into the OnBeforePost event.
When the dataset scrolls without any change in the data of the listbox, there is no need to store any data. This is achieved with the above approach as without edit mode no BeforePost event will fire in this case.
So I'm messing around with a new project in Delphi 2009 and the default components that can be dropped onto a form for accessing data consist of a SQLConnection, DataSource and SQLQuery. If I add a simple select to the query component, say:
select name from customers
and then drop a DBComboBox on the form and link it up with the DataSource I get a single record in the combo box. After using Google for half and hour to figure out what I was doing wrong it looks like you have to manually add some code to your project which loops through the dataset and adds all the records to the drop down box. Something like:
while not SQLQuery.eof do
begin
DBComboBox.items.add(SQLQuery.fieldbyname('name').asstring);
SQLQuery.next;
end;
And that actually sort of works, but then you get a list in the drop down which you can't actually select anything from. Regardless of the result though I'm wondering why would you even use a DBComboBox if you have to manually add the result of your query to it? Seems to me that if it doesn't automatically populate the db combo box with the result of the query then we might as well be using a non-data-aware component like tcombobox.
I guess what I'm asking is why does it work this way? Isn't the purpose of data aware drag-and-drop controls to minimize the amount of actual written code and speed development? Is there a method that I'm missing that is supposed to make this easier?
A TDBComboBox doesn't get its list of values from the database; it gets its current value from the database. Link it to a field in your dataset, and when you change the active record, the combo box's current value will change. Change the combo box's current value, and the corresponding field's value will change.
If you want to get the list of values from the database as well, then use a TDBLookupComboBox.
This is all covered in the help:
Using TDBListBox and TDBComboBox
Displaying and Editing Data in Lookup List and Combo Boxes
Defining a Lookup List Column
I think you want the TDBLookupComboBox because that allows you to lookup from a list of items where the list comes from a dataset.
In the TDBComboBox, the list is just a TStrings manually filled with data.
--jeroen
DbCombox is a dbaware version of the standard combobox component.