.net - How to transfer data from one form to another in winforms c#? -
- i want create @ 5-6 forms in windows application insert data.
- each form contain at-least 15-20 controls. forms belongs different table. same.
- i have created stored "next"named button on each form, such when click on next button information filled on button store where
, in way after storing information on last button submit button dragged, on clicking on submit button data got saved data base. - please tell me how can store data inserted on previous forms , call on click event of submit button.
for having controls on same page , have used these codes insertion.
private void submit_addbtn_click(object sender, eventargs e) { try { //personal data insert personal per = new personal(); per.name = nametxt.text; per.fathername = f_nametxt.text; per.mothername = m_nametxt.text; per.gotra = gotra_txt.text; per.panth = panthcb.text; per.familyhead = fhntext.text; per.educationlvl = edulvlcb.text; per.education = educb.text; per.blood = bloodcb.text; per.gender = genderlist.text; per.marrital = marritalstatus; per.dateofbirth = dobdtp.text; if (new insertaction().insertpersonal(per)) { messagebox.show("personal insertion happen "); } else { messagebox.show(" personal insertion not happen "); } // spouse data insert spouse sps = new spouse(); sps.spousename = s_nametxt.text; sps.spouseeducationlvl = s_edulvlcb.text; sps.spouseeducation = s_educb.text; sps.spouseblood = s_bgcb.text; sps.spousedob = s_dobdtp.text; if (new insertaction().insertspouse(sps)) { messagebox.show(" spouse insertion happen "); } else { messagebox.show(" spouse insertion not happen "); } // resident data insert ressident resi = new ressident(); resi.ressihnumber = ressi_numtxt.text; resi.ressihcmplx = ressi_complextxt.text; resi.ressistrt = ressi_streettxt.text; resi.ressilandmrk = ressi_landtxt.text; resi.ressiarea = ressi_areatxt.text; resi.ressicity = ressi_citytxt.text; resi.ressiphone = convert.toint64(ressi_phnotxt.text); resi.ressimobile = convert.toint64(mobi_notxt.text); if (new insertaction().insertressident(resi)) { messagebox.show(" ressident insertion happen "); } else { messagebox.show(" ressident insertion not happen "); } //occupation data insert occupation ocp = new occupation(); ocp.occuptype = occup_typetxt.text; ocp.occupadd = office_addresstxt.text; ocp.occupnature = occup_naturecb.text; ocp.occupphone = convert.toint64(office_phno1txt.text); ocp.occupmobile = convert.toint64(office_mobnotxt.text); if (new insertaction().insertoccupation(ocp)) { messagebox.show(" occupation insertion happen "); } else { messagebox.show(" occupation insertion not happen "); } }
please me. thank you.
for sending values between 2 forms, may
1-> send values in constructor of second form. may create paramterized constructor , send values when initialize form :
form1 obj = new form1(object);
2-> may take reference in first form in second form.
in second form,
public form1 objform1;
and in first form,
form2 objform2=new form2(); form2.objform1=this;
and can use form2's objform1 refer form1's textbox or control.
edit :
consider want send values form1
form2
in second form must have variable of type form1 refers prev form. in second form,
public form1 objform1;
and need send current instance of form1
form2
as
form2 objform2=new form2(); form2.objform1=this;
i.e. objform1 created in form2 refers instance of form1.
now in form2 may use of form1's control or variable as,
form1.textbox1
or form1.variable
Comments
Post a Comment