public List <courseClass> fetchCourses(int fetch, int jump) { fetch = fetch <= 0 ? 20 : fetch; jump = jump < 0 ? 0 : jump; List <courseClass> response = new List <courseClass>(); try { SqlConnection con = new SqlConnection(data); SqlCommand cmd = new SqlCommand("SELECT * FROM courseData ORDER BY created DESC", con); SqlDataReader Dr; con.Open(); Dr = cmd.ExecuteReader(); while (Dr.Read()) { try { courseClass reader = new courseClass(); //reader.courseId = Dr.GetGuid(0); //reader.name = Dr.GetString(1) == null ? "GeneralName" : Dr.GetString(1); //reader.creator = Dr.GetGuid(2); //reader.company = Dr.GetGuid(3); //reader.status = Dr.GetString(4) == null ? "GeneralName" : Dr.GetString(4); //reader.information = Dr.GetString(5) == null ? "GeneralName" : Dr.GetString(5); //reader.price = Dr.GetInt32(7).ToString() == null ? 0 : Dr.GetInt32(7); //reader.currency = Dr.GetString(8) == null ? "GeneralName" : Dr.GetString(8); //reader.duration = Dr.GetInt32(9).ToString() == null ? 0 : Dr.GetInt32(9); //reader.durationUnit = Dr.GetString(10) == null ? "GeneralName" : Dr.GetString(10); // Experimental reader.courseId = Dr.GetGuid(0); if (Dr.GetString(1) != null) { reader.name = Dr.GetString(1); } if (Dr.GetGuid(2) != null) { reader.creator = Dr.GetGuid(2); } //if (Dr.GetGuid(3) != null) { reader.company = Dr.GetGuid(3); } reader.created = Dr.GetDateTime(4); if (Dr.GetString(5) != null) { reader.status = Dr.GetString(5); } if (Dr.GetString(6) != null) { reader.information = Dr.GetString(6); } reader.price = 49; reader.currency = "EUR"; reader.duration = 6; reader.durationUnit = "DAY"; response.Add(reader); } catch (Exception ex) { courseClass reader = new courseClass(); reader.status = ex.ToString(); response.Add(reader); continue; } } Dr.Close(); con.Close(); if (response.Count <= 0) { for (int i = 0; i < 5; i++) { courseClass reader = new courseClass(); reader.name = "MyCourse" + i; reader.information = "My new Course is about something cool"; response.Add(reader); } } return(response); } catch (SqlException ex) { courseClass reader = new courseClass(); reader.courseId = new Guid(); reader.name = ""; reader.creator = new Guid(); reader.company = new Guid(); reader.created = DateTime.Now; reader.status = ""; reader.information = ex.ToString(); reader.img = ""; reader.price = 0; reader.currency = ""; reader.duration = 0; reader.durationUnit = ""; response.Add(reader); } catch (Exception e) { // Add error reporting courseClass reader = new courseClass(); reader.courseId = new Guid(); reader.name = ""; reader.creator = new Guid(); reader.company = new Guid(); reader.created = DateTime.Now; reader.status = ""; reader.information = e.ToString(); reader.img = ""; reader.price = 1; reader.currency = ""; reader.duration = 1; reader.durationUnit = ""; response.Add(reader); } return(response); }