September 24th, 2012, 05:19 AM
DBLookupComboBox can't detect new data when insert in mysql database
I have problem with my DBLookupComboBox.
I have 3 Forms (Main, Sity and Country). In Form3 (Country) I insert new Country, save and go to EXIT button to close my form3.
Now I'm in Form2 (City) Where I insert Name of City and ZIP code, and in DBLookupComboBox I can't find my new Insert Country. Only when I Close my Application and Open Again I can see my new insert Country in DBLookupComboBox.
How to refresh my DBLookupComboBox to see insert Countrys.
I try with : ADODataSet1.Close;
ADODataSet1.ReQuery(); but no results.
I use ADOConnection1, ADODataSet1 and DataSource1.
September 24th, 2012, 04:57 PM
You don't actually confirm which table is connected to ADODataSet1.
It should be the lookup table of course.
I don't remember offhand the exact property names but isn't there a
If these do not work then are you sure that the insert is part of the same transaction or has been committed?
I do not know if there is something MySQL specific as, personally, I work with Oracle and Firebird 99% of my time.
September 24th, 2012, 11:28 PM
Just refresh the dataset connected to your DBLookupComboBox's ListSource property. The DBLookupComboBox will automatically detect the change of the dataset and update its content accordingly.
In your case, it seems that you are maintaining two different datasets (regarding Country table). One used in Country form and the other one used by the DBLookupComboBox. You can centralized the Country dataset so both use the same one. This way everytime Country form adds new country, the DBLookupComboBox will automatically be updated. You can use TDataModule to host datasets that will be used from many different forms.
September 25th, 2012, 03:13 AM
Thank you "clivew" and "Luthfi" for reply.
Problem is solved. In the Save button (sity and country form) I added
Form2.ADODataSet1.Active: = False; (form2,form3)
Form2.ADODataSet1.Active: = True;, (form2,form3)
in the end I found that I still have a problem.
In TDBLookComboBox the Properties-list sourse I mistake the Form?-> datasource1. rookie mistake!!!
I fixed that and works beautifully.
[In your case, it seems that you are maintaining two different datasets (regarding Country table)]
In my MySql database I have 3 table (Contacts, City and Coutry)
In Form1 I have AdoConnection1, AdoDataSet1 (properties: commandtext:Contacts), DataSource1
AdoDataSet2 (properties: commandtext:city ), DataSource2
TDBLookComboBox1 (Properties - datasource:datasouce1, list source:Form2-> datasource1)
In Form2 I have AdoDataSet1 (properties: commandtext:city), DataSource1
AdoDataSet2 (properties: commandtext:country), DataSource2
TDBLookComboBox1 (Properties-datasource:datasouce1, list source:Form3-> datasource1)
In Form3 I have AdoDataSet1 (properties: commandtext:country), DataSource1
I'm not sure is this 100% correct and nice code, I will move all connections, dataset and datasourse to DataModul.