目前我在同一页面上拥有所有控件,并且我已使用这些代码进行插入。
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 does 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 does 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 does 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 does not Happen ");
}
}
请帮帮我。 谢谢。
答案 0 :(得分:4)
要在两个表单之间发送值,您可以
1→在第二个表单的构造函数中发送值。您可以创建一个参数化构造函数,并在初始化表单时发送值:
Form1 obj = new Form1(Object);
2→您可以在第二种形式中参考您的第一个表格。
第二种形式,
public Form1 objForm1;
并以First Form形式,
Form2 objForm2=new Form2();
Form2.objForm1=this;
然后你可以使用Form2的objForm1来引用Form1的文本框或任何控件。
编辑:
考虑您要将所有值从Form1
发送到Form2
在第二种形式中,您必须有一个Form1类型的变量,它引用了prev形式。所以在第二种形式,
public Form1 objForm1;
然后您需要将Form1
的当前实例发送到Form2
Form2 objForm2=new Form2();
Form2.objForm1=this;
即。您在Form2中创建的objForm1引用此Form1实例。
现在,在Form2中,您可以使用Form1的任何控件或变量作为
Form1.TextBox1
或Form1.Variable