Click here to Skip to main content
14,937,591 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am design One windows Form Application. I am Taken 3 Combo Boxes.First Box Display Country names.Then Select one item display selected country states in second combo box.But I am Select State Then Not Display city's in third combo box.i am using Sql Server database. country names taken as table name.state name as column name,city name as fields.
so Please Give Me Some Idea To Solve This Problem.
Updated 23-Nov-16 5:32am
gqadirshabbir 4-May-12 2:11am
share your code that will clear where the correction is needed ...

The design specified in the question looks like as follows:
1. One table each for each Country.
2. One Column each of each State in each country table.
3. One Field (Row) for each City in each state.

This design is very difficult to implement as any change in No. of Countries requires a change in the No. of Tables in the Database. Similarly any change in the No. of States requires change in the No. of Columns of the corresponding Country table.

A better option is to create three Tables Country, State, City which will store one data item per row for Country, State and City respectively.

Then for the functionality stated in the question, the procedure as detailed in the following answer may be used for Windows Forms Application stated in the question.
3 combobox for country,state and cities.when i select one country that coressponing states will display in 2nd combobox,and when i select one state that coressponing cities will display in...[^]
Sandeep Mewara 4-May-12 10:03am
Good suggestion. 5!
VJ Reddy 4-May-12 10:16am
Thank you, Sandeep.
Shahin Khorshidnia 4-May-12 22:22pm
Good solution VJ.
VJ Reddy 4-May-12 23:38pm
Thank you, Shahin.
hi firstly check for the event of state combobox it must be firing an event.
if if it firing an event then you can write your code in that event as follows

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
SqlConnection conn = new SqlConnection("provide connection string here");
DataSet ds = new DataSet();
SqlDataAdapter da=new SqlDataAdapter("select " + state + " from " + country, conn);
ds.Tables[0]; this will have one column which has all the data of cities for the state and country you've selected
when you are done with this you can bind this ds.tables[0] with your comboBox.
Note:- state and country here are string variables,and they are selected values of respective dropdowns
Mark your answer as solved if you've got the answer
This earlier question[^] may help you.
<ComboBox Grid.Column="8" Grid.Row="8" Height="23" HorizontalAlignment="Left" Name="comboBox2" VerticalAlignment="Center" Width="180">
                <ComboBoxItem Content="Days" />
                <ComboBoxItem Content="Weeks" />
                <ComboBoxItem Content="Months" />
                <ComboBoxItem Content="Years" />
simple example

make 2 tables
first for countries
like this
CountryId CountryName
1 Palestine
2 Germany
3 .......

the second for states
CountryId StateId StateName CiteisName
1 1 Jerusalem abo dees-selawan-shoafat-bait hanena-...
1 2 Gazza gazza-khan yones-rafah-der albalh-...
1 3 Tulkarm Illar-Attil-alnazleh-....
1- first fill the ComboCountries (by code or insert it manualy)
2- when you choose any contry search in the states table like this :
select StateName form states where CountryId = " & CountryId & " oeder by StateName
and fill the combo of states with result
3- when you choose any State search in the states table like this
select CiteisName form states where StateName = '" & compo3 & "' oeder by StateName
Dim CityArry() As String
CityArry() = Split(rs.Fields(0), "-")
For i = 0 To UBound(CityArry)
CompoCiteis.additem CityArry(i)

i hope this help
[no name] 23-Nov-16 11:47am
The question was asked and answered FOUR years ago
The question is clearly marked C# your code is VB
Your code is not formatted
Your code would not compile even if if were C#
Your queries would not work anyway.
Glaring spelling and grammar errors detract from your solution
Having just joined today, maybe you should learn how the web site works before resurrecting ancient already answered questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900