/// <summary> /// I want to read the information from my database and present it to my view. /// </summary> /// <param name="connection"></param> /// <param name="query"></param> public static void ShowReadResultForMajors(string connection, string query) { using (SqlConnection sqlcon = new SqlConnection(connection)) { SqlCommand command = new SqlCommand(query, sqlcon); try { sqlcon.Open(); SqlDataReader reader = command.ExecuteReader(); // the rest was set up; this is what we want. while (reader.Read() && !majorReadClosed) { Major m = new Major((int)reader[0], reader[1].ToString()); University2.AddMajor(m); majorCount++; } majorReadClosed = true; reader.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } } }
public static void WriteStudentsToUniversity(string connection, string query) { using (SqlConnection sqlcon = new SqlConnection(connection)) { SqlCommand command = new SqlCommand(query, sqlcon); try { sqlcon.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read() && !studentReadClosed) { int a = (int)reader[0]; string b = reader[1].ToString(); string c = reader[2].ToString(); string d = reader[3].ToString(); string e = reader[4].ToString(); int f = (int)reader[5]; Status g = (Status)reader[6]; bool h = (bool)reader[7]; Student s = new Student(a, b, c, d, e, f, g, h); University2.AddStudent(s); } studentReadClosed = true; reader.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } } }
/* *-------------------------------------------COURSE STUFF-------------------------------------------------------- */ /// <summary> /// Want to display the names of the course and their availablity. May incorporate them as a sorted table by time. /// </summary> /// <param name="connection"></param> /// <param name="query"></param> public static void ShowReadResultForCourses(string connection, string query) { using (SqlConnection sqlcon = new SqlConnection(connection)) { SqlCommand command = new SqlCommand(query, sqlcon); try { sqlcon.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read() && !courseReadClosed) { int a = (int)reader[0]; string b = reader[1].ToString(); int d = (int)reader[2]; string e = reader[3].ToString(); bool f = (bool)reader[4]; int g = (int)reader[5]; Course c = new Course(a, b, d, e, f, g); University2.AddCourse(c); } courseReadClosed = true; reader.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } } }