示例#1
0
        void DisplayRecords()
        {
            tbl_students _student = new tbl_students();

            using (SampleEntities db = new SampleEntities())
            {
                var stud = db.tbl_students.ToList();
                dataGridView1.DataSource = stud;
            }
        }
示例#2
0
        private void button3_Click(object sender, EventArgs e)
        {
            tbl_students _student = new tbl_students();

            _student.StudentID = txtStudentID.Text;
            using (SampleEntities db = new SampleEntities())
            {
                var stud = db.tbl_students.FirstOrDefault(a => a.StudentID == _student.StudentID);
                db.tbl_students.Remove(stud);
                db.SaveChanges();
            }
            MessageBox.Show("Delete  Successful");
            DisplayRecords();
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //ADD
            tbl_students _student = new tbl_students();

            _student.StudentID  = txtStudentID.Text;
            _student.FirstName  = txtFName.Text;
            _student.LastName   = txtLName.Text;
            _student.MiddleName = txtMName.Text;

            using (SampleEntities db = new SampleEntities())
            {
                db.tbl_students.Add(_student);
                db.SaveChanges();
            }
            MessageBox.Show("Add Successful");
            DisplayRecords();
        }
示例#4
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Update
            tbl_students _student = new tbl_students();

            _student.StudentID  = txtStudentID.Text;
            _student.FirstName  = txtFName.Text;
            _student.MiddleName = txtMName.Text;
            _student.LastName   = txtLName.Text;

            using (SampleEntities db = new SampleEntities())
            {
                var stud = db.tbl_students.FirstOrDefault(a => a.StudentID == _student.StudentID);
                if (stud != null)
                {
                    stud.FirstName  = _student.FirstName;
                    stud.LastName   = _student.LastName;
                    stud.MiddleName = _student.MiddleName;
                    db.SaveChanges();
                }
                MessageBox.Show("Update  Successful");
                DisplayRecords();
            }
        }