protected void Button2_Click(object sender, EventArgs e) { try { EMPDATA E = new EMPDATA(); E.EMPNO = int.Parse(txteno.Text); E.ENAME = txtname.Text; E.JOB = txtjob.Text; E.MGR = int.Parse(txtmid.Text); E.HIREDATE = DateTime.Parse(txtdate.Text); E.SAL = int.Parse(txtsal.Text); E.COMM = int.Parse(txtcom.Text); E.DEPTNO = int.Parse(txtdno.Text); D.EMPDATAs.Add(E); D.SaveChanges(); } catch (DbUpdateException EX) { SqlException ex = EX.GetBaseException() as SqlException; if (ex.Message.Contains("EMP_PK")) { Label1.Text = "no duplicate empno"; } else if (ex.Message.Contains("FK__Empdept")) { Label1.Text = "no dept no"; } else { Label1.Text = ex.Message; } } }
protected void Button1_Click(object sender, EventArgs e) { int eno = int.Parse(Texteno.Text); var E = from E1 in D.EMPDATAs where E1.EMPNO == eno select E1; EMPDATA emp = E.First(); D.EMPDATAs.Remove(emp); D.SaveChanges(); }
protected void Button2_Click(object sender, EventArgs e) { int c = 0; int eno = int.Parse(txteno.Text); var E = from E1 in D.EMPDATAs where E1.EMPNO == eno select E1; EMPDATA emp = E.First(); bool b = int.TryParse(txtcom.Text, out c); emp.ENAME = txtname.Text; emp.JOB = txtjob.Text; emp.MGR = int.Parse(txtmid.Text); emp.HIREDATE = DateTime.Parse(txtdate.Text); emp.SAL = int.Parse(txtsal.Text); if (c != 0) { emp.COMM = c; } emp.DEPTNO = int.Parse(txtdno.Text); D.SaveChanges(); }