1
Answer

I write a piece of code for binding different values into a combobox at run time

Sai Kishore

Sai Kishore

12y
1.1k
1
hi friends i write a piece of code for binding different values into a combobox at run time..  the code is running properly for one value, if i want to add some more values at run time to the same combobox then it is replacing the old values with the new values... i dont want to replace the values..  it has to append the values to the same combobox..

please go thru the code.... as follows...

DataSet dsInv =new DataSet();
                    OleDbDataAdapter dap = new OleDbDataAdapter("select InvestigationName from ServiceInvestigations where BillNo =" + txtBillNo.Text + "", cn);
                    dap.Fill(dsInv, "ServiceInvestigations");
                    dgvReports.DataSource = dsInv.Tables["ServiceInvestigations"];
                    for (int i = 0; i < dgvReports.RowCount - 1; i++)
                    {
                        string tesName = dgvReports.Rows[i].Cells["InvestigationName"].Value.ToString();
                        txtInvestigations.Text = string.Concat(tesName+",",txtInvestigations.Text);


                        if (cn.State == ConnectionState.Open)
                        {
                            cn.Close();
                        }
                        cn.Open();
                       
                        OleDbDataAdapter da = new OleDbDataAdapter("select [Inv_name] from [Investigation] where Lab='"+tesName+"' ", cn);
                        DataTable dt = new DataTable();
                        da.Fill(dt);
                        DataRow dr;
                        dr = dt.NewRow();
                        cmbInvNames.DisplayMember = "Inv_name";
                        cmbInvNames.ValueMember = "Inv_name";
                        cmbInvNames.DataSource = dt;
                        cmbInvNames.Items.Add(item);
                        cmbInvNames.Items.Add(dt);
                        cn.Close();
                       
                       
                    }



Answers (1)