#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    12
    Rep Power
    0

    DBLookupComboBox can't detect new data when insert in mysql database


    Hello,

    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.Open;
    ADODataSet1.ReQuery(); but no results.

    I use ADOConnection1, ADODataSet1 and DataSource1.

    Plese Help.
    Thank You.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,055
    Rep Power
    383
    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
    DBLookupComboBox.LookupDataset.Refresh; option?

    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.

    Clive
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    151
    Rep Power
    2
    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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    12
    Rep Power
    0
    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.

    -Luthfi
    [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.

IMN logo majestic logo threadwatch logo seochat tools logo