Exemplo n.º 1
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            //int eno = int.Parse(txteno.Text);
            //var E1= from i in d.EMPDATAs
            //        where i.EMPNO == eno
            //        select i;
            //EMPDATA E= E1.First();
            int     a = 0;
            bool    c = int.TryParse(txtcomm.Text, out a);
            EMPDATA E = new EMPDATA();

            E.EMPNO    = int.Parse(txteno.Text);
            E.ENAME    = txtename.Text;
            E.JOB      = txtjob.Text;
            E.MGR      = int.Parse(txtmgrid.Text);
            E.HIREDATE = DateTime.Parse(txthd.Text);
            E.SAL      = int.Parse(txtsal.Text);
            if (a != 0)
            {
                E.COMM = a;
            }
            E.DEPTNO         = int.Parse(txtdeptno.Text);
            d.Entry(E).State = System.Data.Entity.EntityState.Modified;
            d.SaveChanges();
            Response.Write("<script>alert('Updated');</script>");
        }
Exemplo n.º 2
0
 //Entity without StoredProcedures
 protected void Button1_Click(object sender, EventArgs e)
 {
     try
     {
         EMPDATA E = new EMPDATA();
         E.EMPNO    = int.Parse(txtEmployeeNo.Text);
         E.ENAME    = txtEmployeeName.Text;
         E.JOB      = txtJob.Text;
         E.MGR      = int.Parse(txtMGR.Text);
         E.HIREDATE = DateTime.Parse(txtHireDate.Text);
         E.SAL      = int.Parse(txtSalary.Text);
         E.COMM     = int.Parse(txtCommission.Text);
         E.DEPTNO   = int.Parse(txtDepartmentNo.Text);
         D.EMPDATAs.Add(E);
         D.SaveChanges();
     }
     catch (DbUpdateException E1)
     {
         SqlException ex = E1.GetBaseException() as SqlException;
         if (ex.Message.Contains("EMP_PK"))
         {
             Label1.Text = "No Duplicate Empno";
         }
         else if (ex.Message.Contains("FK__EMPDATA_DEPTNO"))
         {
             Label1.Text = "No Duplicate Deptno";
         }
         else
         {
             Label1.Text = ex.Message;
         }
     }
 }
Exemplo n.º 3
0
        protected void btninsert_Click(object sender, EventArgs e)
        {
            try
            {
                EMPDATA E = new EMPDATA();
                E.EMPNO    = int.Parse(txteno.Text);
                E.ENAME    = txtename.Text;
                E.JOB      = txtjob.Text;
                E.MGR      = int.Parse(txtmgrid.Text);
                E.HIREDATE = DateTime.Parse(txthd.Text);
                E.SAL      = int.Parse(txtsal.Text);
                E.COMM     = int.Parse(txtcomm.Text);
                E.DEPTNO   = int.Parse(txtdeptno.Text);

                d.EMPDATAs.Add(E);
                d.SaveChanges();
            }
            catch (DbUpdateException M)
            {
                SqlException ex = M.GetBaseException() as SqlException;
                if (ex.Message.Contains("EMP_PK"))
                {
                    label.Text = "No Duplicate Empno is allowed";
                }
                else if (ex.Message.Contains("FK__EMPDept"))
                {
                    label.Text = "Deptno does not exsist";
                }
                else
                {
                    label.Text = ex.Message;
                }
            }
        }
Exemplo n.º 4
0
        protected void Update_Click(object sender, EventArgs e)
        {
            int eno = int.Parse(txtEmployeeNo.Text);
            var E   = from E1 in D.EMPDATAs
                      where E1.EMPNO == eno
                      select E1;
            EMPDATA emp = E.First();
            int     c   = 0;
            bool    b   = int.TryParse(txtCommission.Text, out c);

            emp.ENAME    = txtEmployeeName.Text;
            emp.JOB      = txtJob.Text;
            emp.MGR      = int.Parse(txtMGR.Text);
            emp.HIREDATE = DateTime.Parse(txtHireDate.Text);
            emp.SAL      = int.Parse(txtSalary.Text);
            if (c != 0)
            {
                emp.COMM = c;
            }
            emp.DEPTNO = int.Parse(txtDepartmentNo.Text);
            D.SaveChanges();
        }