Help for a Listbox program using DB

jotis1

Member
Dear Friends,

I need to do a ListBox program.
I have a table called Country.
Fields are country_code and country_name.
I need to use this dropdownbox in a form Customer. Where I need to select a Country from a list box and it will be saved into the Customer table along with other fields.

I need to insert only country_code into customer table and no need of country_name. But in the form, in drop down box (Listbox) I need to show the county_name.

So How I can do this program ?.

My current program is given below

AddListBox ("frmCustomer","ListBoxCountry", 200, 160, 100, 25)
Command.CommandText = "SELECT * FROM t01_country"
Reader.Value = Command.ExecuteReader
Do While Reader.ReadNextRow = True
ListBoxCountry.Add(Reader.GetValue(1))
Loop
Reader.Close


If I use GetValue(0) I will get country_code
If I use GetValue(1) I will get country_name

How I can both, ie
In client side, dropdownbox shows the country_name
but when I click on a Save button, I need the value of country_code.

I am new to Basic4ppc, I think you got the idea,
In HTML.
It is like
<select name='country'>
<option value='IND'>India</option>
<option value='ESP'>Spain</option>
<option value='JPN'>Japan</option>
</select>

I think You got the idea. Could you please give a help to me

rgds
Jotis:sign0085::sign0085:
 
Last edited:

Ariel_Z

Active Member
Licensed User
Try adding an ArrayList. Insert the ID (country_code) to the ArrayList by adding a line after
B4X:
ListBoxCountry.Add(Reader.GetValue(1))
as follows (ArrayList1 is the arraylist you've added):
B4X:
ArrayList1.Add(Reader.GetValue(0))
Then in the SelectionChanged Event, get the value in the right place in the arraylist:
B4X:
countCode = ArrayList1.Item(ListBoxCountry.SelectedIndex)
 
Top