public static List <StudentClass> FindById(int id) { List <StudentClass> currentStudent = new List <StudentClass> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM students WHERE id = " + id + ";"; MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int idz = rdr.GetInt32(0); string name = rdr.GetString(1); DateTime date = (DateTime)rdr.GetDateTime(2); StudentClass newStudent = new StudentClass(name, date.ToString("MM/dd/yyyy"), idz); currentStudent.Add(newStudent); } conn.Close(); if (conn != null) { conn.Dispose(); } return(currentStudent); }
public static List <StudentClass> GetAll() { List <StudentClass> allStudents = new List <StudentClass> { }; MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM students;"; MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int id = rdr.GetInt32(0); string name = rdr.GetString(1); DateTime date = (DateTime)rdr.GetDateTime(2); StudentClass newStudent = new StudentClass(name, date.ToString("MM/dd/yyyy"), id); allStudents.Add(newStudent); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allStudents); }