Esempio n. 1
0
        public static List <CourseClass> FindById(int id)
        {
            List <CourseClass> currentCourse = new List <CourseClass> {
            };
            MySqlConnection conn             = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM courses WHERE id = " + id + ";";
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int         idz       = rdr.GetInt32(0);
                string      name      = rdr.GetString(1);
                string      code      = rdr.GetString(2);
                CourseClass newCourse = new CourseClass(name, code, idz);
                currentCourse.Add(newCourse);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(currentCourse);
        }
Esempio n. 2
0
        public static List <CourseClass> GetAll()
        {
            List <CourseClass> allCourses = new List <CourseClass> {
            };
            MySqlConnection conn          = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM courses;";
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int         id        = rdr.GetInt32(0);
                string      name      = rdr.GetString(1);
                string      code      = rdr.GetString(2);
                CourseClass newCourse = new CourseClass(name, code, id);
                allCourses.Add(newCourse);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allCourses);
        }
Esempio n. 3
0
        public static List <CourseClass> GetCoursesByStudentId(int studentId)
        {
            List <CourseClass> allCourses = new List <CourseClass> {
            };
            MySqlConnection conn          = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT courses.* FROM
                courses JOIN students_courses ON (courses.id = students_courses.course_id)
                    JOIN students ON (students_courses.student_id = students.id)
                WHERE students.id = " + studentId + ";";

            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int         id        = rdr.GetInt32(0);
                string      name      = rdr.GetString(1);
                string      code      = rdr.GetString(2);
                CourseClass newCourse = new CourseClass(name, code, id);
                allCourses.Add(newCourse);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allCourses);
        }