try
{
string reslt = null;
string test;
foreach (Control c in flowLayoutPanel1.Controls) //here is the minor change
{
if (c.GetType() == typeof(ComboBox))
{
reslt = c.Text;
ComboBox combo = (ComboBox)flowLayoutPanel1.Controls.Find(c.Name, true).FirstOrDefault();
test = combo.SelectedValue.ToString();
string insertrec = "insert into testreport(TestID,result,rang,labno,DetailID)Values('" + refid + "','" + reslt + "','0','" + psta + "','" + test + "')";
Program.con.Open();
MySqlCommand insertcmd = new MySqlCommand(insertrec, Program.con);
insertcmd.ExecuteNonQuery();
Program.con.Close();
}
else if (c.GetType() == typeof(TextBox))
{
TextBox testname = (TextBox)flowLayoutPanel1.Controls.Find(c.AccessibleName, true).FirstOrDefault();
reslt = c.Text;
string test1 = c.AccessibleName.ToString();
string insertrec = "insert into testreport(TestID,result,rang,labno,DetailID)Values('" + refid + "','" + reslt + "','0','" + psta + "','" + test1 + "')";
Program.con.Open();
MySqlCommand insertcmd = new MySqlCommand(insertrec, Program.con);
insertcmd.ExecuteNonQuery();
Program.con.Close();
}
else if (c.GetType() == typeof(RichTextBox))
{
// RichTextBoxEx.RichTextBoxEx rich = (RichTextBoxEx.RichTextBoxEx)flowLayoutPanel1.Controls.Find(c.Name,true).FirstOrDefault();
// Richtextboxeditor rich=(Richtextboxeditor)flowLayoutPanel1.Controls.Find(c.Name,true).FirstOrDefault();
RichTextBox rich = (RichTextBox)flowLayoutPanel1.Controls.Find(c.Name, true).FirstOrDefault();
string test2 = c.AccessibleName.ToString();
reslt = c.Text.Replace(@"\", @"\\");
string insertrec = "insert into testreport(TestID,result,rang,labno,DetailID)Values('" + refid + "','" + reslt + "','0','" + psta + "','" + test2 + "')";
Program.con.Open();
MySqlCommand insertcmd = new MySqlCommand(insertrec, Program.con);
insertcmd.ExecuteNonQuery();
Program.con.Close();
}
}
MessageBox.Show("TEST INSERTED SUCCESFULLY !");
flowLayoutPanel1.Controls.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
here is the problem that the loop runs after controls are finished and msg displayed many times.please help me