public static Course Find(int check) { Course ret = new Course(); MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM course where id = " + check + ";"; MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { if (rdr.IsDBNull(0) == false) { ret.SetId(rdr.GetInt32(0)); ret.SetCourseName(rdr.GetString(1)); ret.SetCourseNumber(rdr.GetInt32(2)); } } conn.Close(); if (conn != null) { conn.Dispose(); } return(ret); }
public static List <Course> GetAll() { List <Course> allCourses = new List <Course> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM course;"; MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { Course newCourse = new Course(); newCourse.SetId(rdr.GetInt32(0)); newCourse.SetCourseName(rdr.GetString(1)); newCourse.SetCourseNumber(rdr.GetInt32(2)); allCourses.Add(newCourse); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allCourses); }