Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
string ADDRES = Convert.ToString(comboBox1.SelectedItem);
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "Data source=.;User ID=sa;Password=password;Initial Catalog=bank";
                string sql = "select NAME_PEOPLE from PEOPLE where ADDRESS='@ADDRESS' ";
                SqlCommand cmd=new SqlCommand(sql,con);
                cmd.Parameters.AddWithValue("@ADDRESS", ADDRES);
                 con.Open();
                 SqlDataAdapter ada = new SqlDataAdapter(cmd);
                     
                 DataTable dt = new DataTable();
                    ada.Fill(dt);
                if(comboBox1.SelectedIndex==1)
                {
                        
                     string w=dt.Rows[dt.Rows.Count-1]["NAME_PEOPLE"].ToString();
                            comboBox2.DataSource = dt;
                            comboBox2.DisplayMember = "NAME_PEOPLE";
                }
Posted
Updated 5-Feb-15 17:16pm
v2

1 solution

Hi

Here i added solution please check that

C#
private void Form2_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("a");
            comboBox1.Items.Add("b");
            comboBox1.Items.Add("c");
            comboBox1.Items.Add("d");
            comboBox1.SelectedIndex = -1;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedItem = Convert.ToString(comboBox1.SelectedItem);

            //Instead of this code you can read data from database
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            for(int i=0;i<3;i++)
            {
                dt.Rows.Add(selectedItem + i);
            }


            comboBox2.DataSource = null;
            comboBox2.DataSource = dt;
            comboBox2.DisplayMember = "Name";
        }
 
Share this answer
 

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