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


Sachin SinghRank #66 · 26.2K reputationPosted Feb 27, 2021, 3:02 AM EST
Salman BegRank #284 · 8.8K reputationPosted Feb 27, 2021, 12:55 AM EST
Salman BegRank #284 · 8.8K reputationPosted Feb 27, 2021, 1:36 AM EST
R.D Ip124 reputationPosted Feb 27, 2021, 3:17 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Feb 27, 2021, 3:30 AM EST
R.D Ip124 reputationPosted Feb 27, 2021, 3:40 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Feb 27, 2021, 3:47 AM EST
R.D Ip124 reputationPosted Feb 27, 2021, 3:52 AM EST