Salam,

I am working on a project (windows application), I have used 2 SqlDataReaders in each event of 2 comboBoxes; where each comboBox display either the name of employees or their ID number.
I have also used TextChange event, so if I selected one of the ID the name appear in the other comboBox and vice versa.



this is the code:

Code:
private void comboBox2_TextChanged(object sender, EventArgs e)
        {
            SqlCommand Sc4 = new SqlCommand("select emp_id from employee where emp_fname +' '+ emp_sname +' '+ emp_lname='" + comboBox2.SelectedItem + "'", cn);

            if (cn.State == ConnectionState.Closed)
                cn.Open();
            SqlDataReader rdr = Sc4.ExecuteReader();
            if (rdr.Read())
            {
                comboBox3.Text = rdr["emp_id"].ToString().Trim();
                rdr.Close();
                cn.Close();
            }
            else
            {
                //MessageBox.Show("Not found");
                rdr.Close();
            }
        }

Code:
        private void comboBox3_TextChanged(object sender, EventArgs e)
        {
            SqlCommand Sc5 = new SqlCommand("select emp_fname+' '+ emp_sname+' '+ emp_lname as en from employee where emp_id=" + comboBox3.SelectedItem, cn);

            if (cn.State == ConnectionState.Closed)
                cn.Open();
            SqlDataReader rdr2 = Sc5.ExecuteReader();
            if (rdr2.Read())
            {
                comboBox2.Text = rdr2["en"].ToString().Trim();
                rdr2.Close();
                cn.Close();
            }
            else
            {
                //MessageBox.Show("Not found");
                rdr2.Close();
            }
        }