Example #1
0
        public List <TeacherEnitity> GetTeachers() // Method to get all members in students table
        {
            // Strat connection with database
            DbConnection dbConnection = new DbConnection("spShowTeachers");

            dbConnection.con.Open();
            //DataSet dataSet = new DataSet();
            dbConnection.cmd.ExecuteNonQuery();
            dbConnection.FillData(teacherDataset);
            // Create list to add teachers in
            List <TeacherEnitity> tchList = new List <TeacherEnitity>();

            // Loop to add teachers to the list
            foreach (DataRow dr in teacherDataset.Tables[0].Rows)
            {
                // In each iteration create a new obj of teacher, add values, then push to list
                TeacherEnitity currentTech = new TeacherEnitity();
                currentTech.tchId   = (int)dr[0];
                currentTech.tchName = (string)dr[1];
                tchList.Add(currentTech);
            }

            //Close connection with data-base
            dbConnection.con.Close();
            // return the list of teachers
            return(tchList);
        }
Example #2
0
        private void _ٍShowTeach_Load(object sender, EventArgs e)
        {
            // Create object from TeacherEntity to access GetTeacher method
            TeacherEnitity teacherEntity = new TeacherEnitity();
            // Create new list to save the teacher list returned from GetTeacher method
            List <TeacherEnitity> techList = teacherEntity.GetTeachers();

            // Show the content of teacher list on DataGridView
            dataGridView2.DataSource = techList;
        }
Example #3
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            // create object from TeacherEntity
            TeacherEnitity tachertEntity = new TeacherEnitity();
            // Get course id to inesrt it to database
            int crsId = tachertEntity.GetCourseId(coursesComboBox.Text);

            // Passing teacher name to the object along with course id
            tachertEntity.SetTchByName(txtTchName.Text, crsId);
            // Confirm to user
            MessageBox.Show("Teacher added successfully!");
        }