Why Is My Combo Limited To The List

YASSINE_MAKKE

New member
Joined
Aug 28, 2005
Messages
4
Programming Experience
Beginner
HI ALL
im new to vb.net and moving from msaccess and its a rough ride
so please bare with me.
ok here is the senario
table "students"
with fields (StudentIdPk , StudentName , Country)
im trying to lookup the field "country" and put all the distinct values from this field into the combobox's list. I populate it through dataview code in the load event. It populates fine and i thought i was done.
what is happening is that when the user drops down the list and doesnt find what he wants from the list he tries to add a value from out side the list by writting it down and then presses the update button.
What happens is that it gets cleared and does not update although i was able to do it easly in msaccess .

i tried this problem with sql server and ms access database the problem is the same

what should i do?
please help....
any help will be appreciated.
 
Hmm ... i beleive so that you should improve your DB design there. It is very poor designed if i may. It should be that countries are stored in separate table ... you cannot use distinct in this case as there could be more than two users with same country of residence.
Well, after you make a new table "countries" On_load populate combo from countries table and then just change its text property depending on where current student comes from.

I assume you have something like this:

strSQL = "SELECT DISTINCT country FROM students"

but now change it to look as it follows:
1st populate combo with countries
strSQL="SELECT country FROM Countries"
'execute reader here
While reader.read
cmbCountry.Items.add(reader("country"))
End while

then:

strSQL = "SELECT * FROM students WHERE StudentIdPk='" & yourCondition & "'"
'execute reader here
While reader.read
cmbCountry.Items.add(reader("country"))
cmbName.Items.add(reader("StudentName"))
End while


Cheers ;)
 
thank you kulrom
my students table has about 9-10 of this type of combos if i should make a table for each it would be a complication dont you think but if there are any suggestions im open for it.
i need all the help that i can get.
ok here is the little app that explains exatly what my problem is
i used northwind.mdb as the backend, the behaivior is the same with sql server
now to edit a record use the city combo and enter a city that is not in the list "new city"
and try to update the record
if you add a new record the same thing happens
i will try what you are saying i will back soon
 

Attachments

  • COMBOBOX PROBLEM.zip
    82.3 KB · Views: 23
Back
Top