Exemplo n.º 1
0
        private void GetData()
        {
            ContactsDataContext dbContext = new ContactsDataContext();

            //linq getting from store procedure
            GridView1.DataSource = dbContext.GetEmployee();
            GridView1.DataBind();
        }
Exemplo n.º 2
0
        protected void btnGetEmployeeByDepartment_Click(object sender, EventArgs e)
        {
            using (ContactsDataContext dbContext = new ContactsDataContext())
            {
                string deptName = string.Empty;
                GridView1.DataSource = dbContext.GetEmployeesByDepartment(1, ref deptName);
                GridView1.DataBind();

                lblDept.Text = "Department Name = " + deptName;
            }
        }
Exemplo n.º 3
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            using (ContactsDataContext dbContext = new ContactsDataContext())
            {
                Employee employee = dbContext.Employees.SingleOrDefault
                                        (x => x.ID == 8);
                dbContext.Employees.DeleteOnSubmit(employee);
                dbContext.SubmitChanges();
            }

            GetData();
        }
Exemplo n.º 4
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            using (ContactsDataContext dbContext = new ContactsDataContext())
            {
                Employee employee = dbContext.Employees.SingleOrDefault
                                        (x => x.ID == 8);
                employee.Salary = 6500;
                dbContext.SubmitChanges();
            }

            GetData();
        }
Exemplo n.º 5
0
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            using (ContactsDataContext dbContext = new ContactsDataContext())
            {
                Employee newEmployee = new Employee
                {
                    FirstName    = "Time",
                    LastName     = "T",
                    Gender       = "Male",
                    Salary       = 5000,
                    DepartmentId = 1
                };

                dbContext.Employees.InsertOnSubmit(newEmployee);
                dbContext.SubmitChanges();
            }

            GetData();
        }