Click here to Skip to main content
15,608,157 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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 8-Feb-22 18:23pm
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...[^]
Share this answer
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
Share this answer
This earlier question[^] may help you.
Share this answer
<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" />
Share this answer
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
Share this answer
[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.
Now run the applicationusing System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace CountryStateCity
public partialclass WebForm1 : System.Web.UI.Page
private SqlConnection conn = new SqlConnection("Data source=.; uid=sa; pwd=Password$2; database=CountryStateCity");

public void Bind_ddlCountry()
SqlCommand cmd =new SqlCommand("select County,CountryId from Country", conn);
SqlDataReader dr = cmd.ExecuteReader();
ddlcountry.DataSource = dr;
ddlcountry.Items.Add("--Please Select country--");
ddlcountry.DataTextField = "County";
ddlcountry.DataValueField = "CountryId";
public void Bind_ddlState()

SqlCommand cmd =new SqlCommand("select State,StateID from countryState where CountryId='" + ddlcountry.SelectedValue +"'", conn);

SqlDataReader dr = cmd.ExecuteReader();
ddlstate.DataSource = dr;
ddlstate.Items.Add("--Please Select state--");
ddlstate.DataTextField = "State";
ddlstate.DataValueField = "StateID";
public void Bind_ddlCity()
SqlCommand cmd =new SqlCommand("select * from stateCity where StateId ='" + ddlstate.SelectedValue +"'", conn);

SqlDataReader dr = cmd.ExecuteReader();
ddlcity.DataSource = dr;
ddlcity.Items.Add("--Please Select city--");
ddlcity.DataTextField = "City";
ddlcity.DataValueField = "CityID";
protectedvoid Page_Load(object sender, EventArgs e)
if (!IsPostBack)
protectedvoid ddlcountry_SelectedIndexChanged(object sender, EventArgs e)
protectedvoid ddlstate_SelectedIndexChanged(object sender, EventArgs e)
Now run the application
Share this answer
Shloka Patel 9-Feb-22 0:25am    
I have an ddlcountry and all eror and i have used combobox
Graeme_Grant 9-Feb-22 1:29am    
You do realize that you answered a 10-year-old question? Please focus on current 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