I am working on windows form application c sharp
I am trying to fetch statename based on country in combobox
now I am stuck and my logic is not work,which place need to correction
first I fetch a country name in combobox successfully
now I am trying to fetch statename based on country but my logic is not work
sp : load country
sp : load state based on country
code:
- private void Form1_Load_1(object sender, EventArgs e) //load country successfully in combobox
- {
- cnnString.Open();
- SqlCommand cmd = new SqlCommand("sp_LoadCountry", cnnString);
-
- SqlDataReader reader = cmd.ExecuteReader();
- DataTable dt = new DataTable();
- dt.Columns.Add("countryid");
- dt.Columns.Add("countryname");
- dt.Load(reader);
-
- countrycomboBox.ValueMember = "countryid";
- countrycomboBox.DisplayMember = "countryname";
- countrycomboBox.DataSource = dt;
-
- cnnString.Close();
-
- }
-
- private void countrycomboBox_SelectedIndexChanged(object sender, EventArgs e) //here I am stuck state not load based on country
- {
- SqlCommand cmd = new SqlCommand("sp_LoadStateBaseOnCountry", cnnString);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("countryid",countrycomboBox.Items.IndexOf(cmd));
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- da.Fill(dt);
- statecomboBox.ValueMember = "stateid";
- statecomboBox.DisplayMember = "statename";
- statecomboBox.DataSource = dt;
- }
output:
now I am stuck in logic need help