예제 #1
0
        protected void getDepartments()
        {
            // connect to db
            var conn = new ContosoEntities();

            // run the query using LINQ
            var Departments = from d in conn.Departments
                              select d;

            // display query result in gridview
            gridDepartments.DataSource = Departments.ToList();
            gridDepartments.DataBind();
        }
예제 #2
0
        protected void getStudent()
        {
            // connect to db
            var conn = new ContosoEntities();

            // run the query using LINQ
            var Student = from d in conn.Student
                          select d;

            // display query result in gridview
            grdstudents.DataSource = Student.ToList();
            grdstudents.DataBind();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            var conn = new ContosoEntities();

            //use department class of the new department object
            Department d = new Department();

            d.Name   = txtName.Text;
            d.Budget = Convert.ToDecimal(txtBudget.Text);

            //save the new object into the database
            conn.Departments.Add(d);
            conn.SaveChanges();

            //redirect to department page
            Response.Redirect("departments.aspx");
        }
예제 #4
0
        protected void Savebtn_Click(object sender, EventArgs e)
        {
            //connect
            var conn = new ContosoEntities();

            //use the s class of the new department object
            Student d = new Student();

            d.FirstMidName = txtFirstName.Text;
            d.LastName     = txtLastName.Text;

            d.EnrollmentDate = DateTime.ParseExact(txtDate.Text, "dd/MM/yyyy", null);

            //save the new object into the database
            conn.Student.Add(d);
            conn.SaveChanges();

            //redirect to department page
            Response.Redirect("student.aspx");
        }
예제 #5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            var conn = new ContosoEntities();

            //use the department class to creat a new department object
            Student s = new Student();

            //fill the properties of the new department object
            s.FirstMidName   = txtLastName.Text;
            s.LastName       = txtFirstName.Text;
            s.EnrollmentDate = Convert.ToDateTime(txtEnrollemntDate.Text);


            //Save the new object to the database
            conn.Students.Add(s);
            conn.SaveChanges();

            //redirect to the departments page
            Response.Redirect("students.aspx");
        }