ListBox with foreign key
Posted: Sun Feb 11, 2018 6:17 pm
Hello,
Please I need help with using a listbox control with a foreign key poiting to another table.
What I want to achieve: in my table "costumer" there is a "country" column (INT) which is a 1-to-n relation to an "Id" (primary key) column in another table ("countries").
I have a form with a listbox control whose SQL content is: SELECT `countryname`, `Id` FROM `countries` ORDER BY `countryname` ASC. The bound field is set to 1. I assume then that it will display the countryname in the list but the Id value is what will be actually set in the field.
The list populates perfectly with the values. However when I add a new row, or I try to edit another one, an error is thrown saying that it was unable to update the current register. If I click on "more", it says: SQL state: HY000.
Any ideas? Thank you in advance.
Please I need help with using a listbox control with a foreign key poiting to another table.
What I want to achieve: in my table "costumer" there is a "country" column (INT) which is a 1-to-n relation to an "Id" (primary key) column in another table ("countries").
I have a form with a listbox control whose SQL content is: SELECT `countryname`, `Id` FROM `countries` ORDER BY `countryname` ASC. The bound field is set to 1. I assume then that it will display the countryname in the list but the Id value is what will be actually set in the field.
The list populates perfectly with the values. However when I add a new row, or I try to edit another one, an error is thrown saying that it was unable to update the current register. If I click on "more", it says: SQL state: HY000.
Any ideas? Thank you in advance.