mpdph09 0 Newbie Poster

HI, I am new to C# programming, I am trying to populate data from databse using adatpter and dataset. I am missing some part in my code, that fails to update selected item at selectindexchnaged. Same part works fine at every form_load.

DataSet sdnew = new DataSet();
                    SqlConnection conn01 = new SqlConnection();
                    conn01.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString;
                    SqlCommand comd2 = new SqlCommand("GetBatch", conn01);
                    comd2.CommandType = CommandType.StoredProcedure;
                    comd2.CommandText = "usp_CAMR_BatchStatus";
                    comd2.Connection = conn01;
                    comd2.Parameters.AddWithValue("@batch_name", comboBox1.Text.ToString().Substring(0, 12));
                    comd2.Parameters.AddWithValue("@ERR_CODE", 0);
                    comd2.Parameters.AddWithValue("@ERR_MSG", 0);
                    comd2.Parameters.AddWithValue("@TABLE_NAME", "");
                    SqlDataAdapter dapt001 = new SqlDataAdapter(comd2);
                    dapt001.Fill(sdnew);
                    try
                    {
                        conn01.Open();
                        for (int z = 0; z < comboBox1.Items.Count; z++)
                        {
                            for (int a = 0; a < sdnew.Tables[0].Rows.Count; a++)
                            {
                                if (comboBox1.Items[z].ToString() == sdnew.Tables[0].Rows[a][0].ToString())
                                {
                                    comboBox1.Items.Add(comboBox1.Items[z] + " - " + sdnew.Tables[0].Rows[a][1].ToString());
                                    comboBox1.Items.Remove(comboBox1.Items[z]);

                                }
                            }
                        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.