elham deljooei

elham deljooei

  • NA
  • 84
  • 73.3k

How to put a variable in the name of contorols, txt[i]?

Jan 25 2013 2:53 AM
Hi everyone
i have some Textboxes and lables. their names is txt1,txt2,...and lbl1,lbl2,.... I want to put 'i' rather than 1 ro 2... fro ex: lbl[i](=lbl1). i have to put i rather than 1 when i can send all lbl or txt . but when i run, in highlight line has this eeror "eeror Sequence contains no elements"

 SqlCommand cmd = new SqlCommand("ClerkEvaluation_Insert", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    for (int i = 1; i <= 10; i++)
                    {


                        cmd.Parameters.AddWithValue("@clrk_Name", txtNameClerkEvaluation.Text);
                        cmd.Parameters.AddWithValue("@clrk_Family", txtFamilyClerkEvaluation.Text);
                        cmd.Parameters.AddWithValue("@clrk_MelliCode", txtMelliCodeClerkEvaluation.Text);
                        //cmd.Parameters.AddWithValue("@epcnt_Name", "?????");
                        //cmd.Parameters.AddWithValue("@clrke_Percent", lbl1MadrakeTahsili[i].Name.su
                        //cmd.Parameters.AddWithValue("@clrke_Tozihat", txtRaftar[i].);
                        cmd.Parameters.AddWithValue("@i", i);
                        MessageBox.Show(Convert.ToString(i));
                        cmd.Parameters.AddWithValue("@clrke_Percent", this.Controls.Find(string.Format("lbl{0}", i), false).First().Text);
                        cmd.Parameters.AddWithValue("@clrke_Percent", this.Controls.Find(string.Format("txt{0}", i), false).First().Text);
                        cmd.ExecuteNonQuery();
                        conn.Close();

Answers (1)