Skip to content Skip to sidebar Skip to footer

Combobox Population Based On Each Other Sql C#

i have 2 boxes, i'd like to populate the 1st from sql and the 2nd based on the first (querying sql too) public void Country() { using (SqlConnection conn = new SqlConn

Solution 1:

SELECTDISTINCT CityName FROM City where CountryName =@CountryName

Change the select statement with where clause as above,then you can set the parameter value using this.country.SelectedValue

You can load the second combobox on first combobox selelected index changed event. Call the City() inside first combobox selected index changed event with the where condition to filter city based on country

few links for related code:

c# Using Parameters.AddWithValue in SqlDataAdapter

Cascading ComboBox In Windows Application Using C#

Post a Comment for "Combobox Population Based On Each Other Sql C#"