Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass large number of parameters to a constructor?
    primarykey
    data
    text
    <p>I am having a <b> main form named "add.cs" </b>containing user information (its name , age ....etc.) on this form i have drag a button to add the user's children information (their name , blood group , date of birth..etc)whose click event opens a form "addchild.cs" on which i have dragged two button one for stroring data and another to add controls at runtime. To add controls at runtime i have used this coding</p> <pre><code> private void button1_Click(object sender, EventArgs e) { try { childrenCount++; Label lblchild = new Label(); lblchild.BorderStyle = BorderStyle.Fixed3D; lblchild.Location = new Point(20, (childrenCount - 1) * 50); lblchild.Size = new System.Drawing.Size(50, 20); lblchild.Text = "Child " + (childrenCount - 1); TextBox tName = new TextBox(); //TextBox for the name tName.BorderStyle = BorderStyle.Fixed3D; tName.Location = new Point(120, (childrenCount - 1) * 50); tName.Size = new System.Drawing.Size(135, 60); tName.Text = ""; DateTimePicker calendar = new DateTimePicker(); //MonthCalendar calendar = new MonthCalendar(); //Calendar to choose the birth date calendar.Location = new Point(310, (childrenCount - 1) * 50); ComboBox bloodGroup = new ComboBox(); //ComboBox for the blood group bloodGroup.Location = new Point(650, (childrenCount - 1) * 50); bloodGroup.Size = new System.Drawing.Size(135, 60); for (Enum.Blood_Group l = Enum.Blood_Group.O_negative; l &lt;= Enum.Blood_Group.AB_positive; l++) { bloodGroup.Items.Add(l); } this.panel1.Controls.Add(lblchild); this.panel1.Controls.Add(tName); this.panel1.Controls.Add(calendar); this.panel1.Controls.Add(bloodGroup); } catch (Exception ex) { MessageBox.Show(ex.Message); } } </code></pre> <p>Now I have created a separate <b>external class named "Childrendata"</b> for storing the value of controls added on " addchild.cs". These class contains all the data that i want to store.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Jain_milan { class Childrendata { string childname, childblood, childbirth; public string Childbirth { get { return childbirth; } set { childbirth = value; } } public string Childblood { get { return childblood; } set { childblood = value; } } public string Childname { get { return childname; } set { childname = value; } } } } </code></pre> <p>then on the click event of the submission button on addchild.cs i have used this code to store the controls data to the variables of external class called Childdata.cs.</p> <pre><code> private void submitbtn_Click(object sender, EventArgs e) { //Checks the values try { string message = ""; foreach (Control c in this.Controls) { //loop throught the elements of the form if (c.GetType() == typeof(Panel)) { //check if the control is a Panel //Get the values from the input fields and add it to the message string Panel panel1 = (Panel)c; Label lblchild = (Label)(c.Controls[0]); TextBox tName = (TextBox)(c.Controls[1]); DateTimePicker calendar = (DateTimePicker)(c.Controls[2]); ComboBox bloodGroup = (ComboBox)(c.Controls[3]); //add to class Childrendata childdata=new Childrendata(); childdata.Childname = tName.Text; childdata.Childblood= bloodGroup.Text; childdata.Childbirth=calendar.Text; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } </code></pre> <p>Now how can i made the constructor taking array or any other thing as parameter and that store all the values and i can call this constructor to my main page named add.cs .So on click event of a button on add.cs i may store these values into database by using coding like this.</p> <pre><code>Childrendata cd = new Childremdata(); Children child = new Children(); child.Namechild = cd.Childname; child.Bloodchild = cd.Childblood; child.Dobchild = cd.Childbirth; if (new InsertAction().Insertchildren(child)) { MessageBox.Show(" Children Insertion Happen "); } else { MessageBox.Show(" Children Insertion does not Happen "); } </code></pre> <p>Please tell me the exact example because i have tried a-lot to solve this but no output!! Please help please please please</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload