public bool SaveStudentDetails(StudentDetail Stu) // calling SaveStudentMethod for insert a new record { bool result = false; using (StudentInformationEntities _entity = new StudentInformationEntities()) { _entity.StudentDetails.AddObject(Stu); _entity.SaveChanges(); result = true; } return(result); }
public bool DeleteStudentDetails(StudentDetail Stu) // DeleteStudentDetails method to delete record from table { bool result = false; using (StudentInformationEntities _entity = new StudentInformationEntities()) { StudentDetail _student = _entity.StudentDetails.Where(x => x.Id == Stu.Id).Select(x => x).FirstOrDefault(); _entity.StudentDetails.DeleteObject(_student); _entity.SaveChanges(); result = true; } return(result); }
public bool UpdateStudentDetails(StudentDetail Stu) // UpdateStudentDetails method for update a existing Record { bool result = false; using (StudentInformationEntities _entity = new StudentInformationEntities()) { StudentDetail _student = _entity.StudentDetails.Where(x => x.Id == Stu.Id).Select(x => x).FirstOrDefault(); _student.Name = Stu.Name; _student.Age = Stu.Age; _student.City = Stu.City; _student.Gender = Stu.Gender; _entity.SaveChanges(); result = true; } return(result); }
public void Display() { using (StudentInformationEntities _entity = new StudentInformationEntities()) { List <StudentInformation> _studentList = new List <StudentInformation>(); _studentList = _entity.StudentDetails.Select(x => new StudentInformation { Id = x.Id, Name = x.Name, Age = x.Age, City = x.City, Gender = x.Gender }).ToList(); dataGridView1.DataSource = _studentList; } }