Updating value member of a combobox
<p>I have a code that generates the sum of the fields represented by the value member of a combobox item.Number of comboboxes you choose is the number of items added.
However my code doesnot update the valuemember when its displaymember is changed, and the sum displayed is the sum of item represented by the valuemember of the first combobox only.
See the code:-</p>

<pre><code>SqlCommand cmd = new SqlCommand();
            cmd.Connection = Program.con;
            cmd.CommandText = "Insert Into addtreat values(@tno,@pname,@teeth,@pro,@dname)";
            tno = CommonFunction.GetNextValue(5);
            cmd.Parameters.AddWithValue("@tno", tno);
            cmd.Parameters.AddWithValue("@pname", txtName.Text);
            cmd.Parameters.AddWithValue("@teeth", txtTeeth.Text);
            cmd.Parameters.AddWithValue("@dname", cbDocName.Text);
            if (rbEight.Checked == true)
            {
                proce = cmb1.Text + "," + cmb2.Text + "," + cmb3.Text + "," + cmb4.Text + "," + cmb5.Text + "," + cmb6.Text + "," + cmb7.Text + "," + cmb8.Text;
                SqlDataAdapter d = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb1.ValueMember, Program.con);
                DataTable t = new DataTable();
                d.Fill(t);
                foreach (DataRow row in t.Rows)
                {

                    c1 = Convert.ToInt32(row[0]);
                }
                SqlDataAdapter qd = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb2.ValueMember, Program.con);
                DataTable qt = new DataTable();
                qd.Fill(qt);
                foreach (DataRow row in qt.Rows)
                {

                    c2 = Convert.ToInt32(row[0]);
                }
            }
            else if (rbThree.Checked == true)
            {
                proce = cmb1.Text + "," + cmb2.Text + "," + cmb3.Text;
                SqlDataAdapter d = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb1.ValueMember, Program.con);
                DataTable t = new DataTable();
                d.Fill(t);
                foreach (DataRow row in t.Rows)
                {

                    c1 = Convert.ToInt32(row[0]);
                }
                SqlDataAdapter qd = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb2.ValueMember, Program.con);
                DataTable qt = new DataTable();
                qd.Fill(qt);
                foreach (DataRow row in qt.Rows)
                {

                    c2 = Convert.ToInt32(row[0]);
                }
                SqlDataAdapter wd = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb3.ValueMember, Program.con);
                DataTable wt = new DataTable();
                wd.Fill(wt);
                foreach (DataRow row in wt.Rows)
                {

                    c3 = Convert.ToInt32(row[0]);
                }
            }
 cmd.Parameters.AddWithValue("@pro", proce);
            sum = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8;

            cmd.ExecuteNonQuery();
</code></pre>

<p>Need urgent help
Heres the combobox code:-</p>

<pre><code>private void frmTreatment_Load(object sender, EventArgs e)
        {
            SqlDataAdapter adp = new SqlDataAdapter("select * from adddoc", Program.con);
            DataTable tb = new DataTable();
            adp.Fill(tb);

            cbDocName.DataSource = tb;
            cbDocName.DisplayMember = "DName";
            cbDocName.ValueMember = "SSN";

            SqlDataAdapter ap = new SqlDataAdapter("select * from addpro", Program.con);
            DataTable t = new DataTable();
            ap.Fill(t);
            cmb1.DataSource = t;
            cmb1.DisplayMember = "ProcedureName";
            cmb1.ValueMember = "SSN";
            SqlDataAdapter qqap = new SqlDataAdapter("select * from addpro", Program.con);
            DataTable qqt = new DataTable();
            qqap.Fill(qqt);

            cmb2.DataSource = qqt;
            cmb2.DisplayMember = "ProcedureName";
            cmb2.ValueMember = "SSN";
            SqlDataAdapter qap = new SqlDataAdapter("select * from addpro", Program.con);
            DataTable qt = new DataTable();
            qap.Fill(qt);

            cmb3.DataSource = qt;
            cmb3.DisplayMember = "ProcedureName";
            cmb3.ValueMember = "SSN";

        }
</code></pre>
