public Dictionary<string, Curs> GetCurses() { Dictionary<string, Curs> curses = new Dictionary<string,Curs>(); using (SqlConnection Connection = GetConnection()) { Connection.Open(); SqlCommand command = new SqlCommand("SELECT * FROM Curs", Connection); SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { Curs curs = new Curs() { CursID = (int)dataReader["cursID"], Name = (string)dataReader["name"], ModuleID = (int)dataReader["modulID"], CreditPoints = (int)dataReader["creditPoints"], Description = dataReader["description"] == DBNull.Value ? string.Empty : (string)dataReader["description"] }; curses.Add(curs.Name, curs); } } return curses; }
public List<Curs> GetCursesByModul(int modulID) { List<Curs> curses = new List< Curs>(); using (SqlConnection Connection = GetConnection()) { Connection.Open(); SqlCommand command = new SqlCommand("SELECT * FROM Curs WHERE modulID = @modulID", Connection); command.Parameters.AddWithValue("@modulID", modulID); SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { Curs curs = new Curs() { CursID = (int)dataReader["cursID"], Name = (string)dataReader["name"], ModuleID = (int)dataReader["modulID"], CreditPoints = (int)dataReader["creditPoints"], Description = dataReader["description"] == DBNull.Value ? string.Empty : (string)dataReader["description"] }; curses.Add( curs); } } return curses; }