title: For IF Loop not working correctly
body: <p>I am trying to use a for-if loop to run through a few CheckBoxList controls, to see if a checkbox is checked. If checked, it will run an INSERT statement to the DB. </p>
  
  <p>My first CheckBoxList (stapleCheckBoxList) works as it should (Eg. If i selected all 4 checkboxes, the corresponding items will be inserted into the db). However for my second CheckBoxList (seafoodCheckBoxList), it seems to only do an INSERT on the first checkbox that is selected. Could anyone identify whats wrong with my codes below?</p>
  
  <pre><code>protected void btnTSubmit_Click(object sender, EventArgs e)
      {
          int i;
          int intOrderNo = (int)Session["sOrderNo"];
          int Qty;
          int UnitPrice;
          string ProdId;
  
          if (txtPaxQty.Text != String.Empty)
          {
              UnitPrice = 12;
              Qty = int.Parse(txtPaxQty.Text);
              ProdId = "PK001";
  
              OleDbConnection DBconn2 = new OleDbConnection();
              DBconn2.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data source="
                          + Server.MapPath("~/App_Data/ParissDB.mdb");
              OleDbCommand cmd = new OleDbCommand();
              cmd.Connection = DBconn2;
              cmd.CommandType = System.Data.CommandType.Text;
              cmd.CommandText = "INSERT INTO itemsTable(iOrderNo, iProductId, iQty, iUnitPrice)"
              + "VALUES (@OrderNo, @ProductId, @Qty, @UnitPrice)";
              cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
              cmd.Parameters.AddWithValue("@ProductId", ProdId);
              cmd.Parameters.AddWithValue("@Qty", Qty);
              cmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
              DBconn2.Open();
              cmd.ExecuteNonQuery();
              DBconn2.Close();
          }
  
          for (i = 0; i &lt; stapleCheckBoxList.Items.Count; i++)
          {
              String str = "";
  
              if (stapleCheckBoxList.Items[i].Selected)
              {
  
                  str = stapleCheckBoxList.Items[i].Text;
  
                  OleDbConnection DBconn = new OleDbConnection();
                  DBconn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data source="
                              + Server.MapPath("~/App_Data/ParissDB.mdb");
  
                  Qty = 0;
                  UnitPrice = 0;
  
                  OleDbCommand cmd = new OleDbCommand();
                  cmd.Connection = DBconn;
                  cmd.CommandType = System.Data.CommandType.Text;
                  cmd.CommandText = "INSERT INTO itemsTable(iOrderNo, iProductId, iQty, iUnitPrice)"
                  + "VALUES (@OrderNo, @ProductId, @Qty, @UnitPrice)";
  
                  //Staple
  
                  if (stapleCheckBoxList.Items[i].Text == "Yang Chow Fried Rice")
                  {
                      str = "ST001";
                      cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
                      cmd.Parameters.AddWithValue("@ProductId", str);
                      cmd.Parameters.AddWithValue("@Qty", Qty);
                      cmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
                      DBconn.Open();
                      cmd.ExecuteNonQuery();
                      DBconn.Close();
                  }
  
                  if (stapleCheckBoxList.Items[i].Text == "Pineapple Fried Rice")
                  {
                      str = "ST002";
                      cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
                      cmd.Parameters.AddWithValue("@ProductId", str);
                      cmd.Parameters.AddWithValue("@Qty", Qty);
                      cmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
                      DBconn.Open();
                      cmd.ExecuteNonQuery();
                      DBconn.Close();
                  }
  
                  if (stapleCheckBoxList.Items[i].Text == "Mee Goreng")
                  {
                      str = "ST003";
                      cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
                      cmd.Parameters.AddWithValue("@ProductId", str);
                      cmd.Parameters.AddWithValue("@Qty", Qty);
                      cmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
                      DBconn.Open();
                      cmd.ExecuteNonQuery();
                      DBconn.Close();
                  }
  
                  if (stapleCheckBoxList.Items[i].Text == "Fried Udon with Seafood")
                  {
                      str = "ST004";
                      cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
                      cmd.Parameters.AddWithValue("@ProductId", str);
                      cmd.Parameters.AddWithValue("@Qty", Qty);
                      cmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
                      DBconn.Open();
                      cmd.ExecuteNonQuery();
                      DBconn.Close();
                  }
  
  
                  //Response.Redirect("Delivery.aspx");
              }
          }
  
          for (i = 0; i &lt; seafoodCheckBoxList.Items.Count; i++)
          {
              String str2 = "";
  
              if (seafoodCheckBoxList.Items[i].Selected)
              {
  
                  str2 = seafoodCheckBoxList.Items[i].Text;
  
                  OleDbConnection DBconn = new OleDbConnection();
                  DBconn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data source="
                              + Server.MapPath("~/App_Data/ParissDB.mdb");
  
                  Qty = 0;
                  UnitPrice = 0;
  
                  OleDbCommand cmd = new OleDbCommand();
                  cmd.Connection = DBconn;
                  cmd.CommandType = System.Data.CommandType.Text;
                  cmd.CommandText = "INSERT INTO itemsTable(iOrderNo, iProductId, iQty, iUnitPrice)"
                  + "VALUES (@OrderNo, @ProductId, @Qty, @UnitPrice)";
  
                  //Seafood
  
                  if (seafoodCheckBoxList.Items[i].Text == "Butter Prawns")
                  {
                      str2 = "SE002";
                      cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
                      cmd.Parameters.AddWithValue("@ProductId", str2);
                      cmd.Parameters.AddWithValue("@Qty", Qty);
                      cmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
                      DBconn.Open();
                      cmd.ExecuteNonQuery();
                      DBconn.Close();
                  }
  
                  if (seafoodCheckBoxList.Items[i].Text == "Cereal Prawns")
                  {
                      str2 = "SE001";
                      cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
                      cmd.Parameters.AddWithValue("@ProductId", str2);
                      cmd.Parameters.AddWithValue("@Qty", Qty);
                      cmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
                      DBconn.Open();
                      cmd.ExecuteNonQuery();
                      DBconn.Close();
                  }
  
                  if (seafoodCheckBoxList.Items[i].Text == "Thai Style Prawns")
                  {
                      str2 = "SE003";
                      cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
                      cmd.Parameters.AddWithValue("@ProductId", str2);
                      cmd.Parameters.AddWithValue("@Qty", Qty);
                      cmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
                      DBconn.Open();
                      cmd.ExecuteNonQuery();
                      DBconn.Close();
                  }
  
                  if (seafoodCheckBoxList.Items[i].Text == "BBQ Squid")
                  {
                      str2 = "SE004";
                      cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
                      cmd.Parameters.AddWithValue("@ProductId", str2);
                      cmd.Parameters.AddWithValue("@Qty", Qty);
                      cmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
                      DBconn.Open();
                      cmd.ExecuteNonQuery();
                      DBconn.Close();
                  }
  
                  Response.Redirect("Delivery.aspx");
              }
  
          }
  </code></pre>