Ejemplo n.º 1
0
        public static List<ProgrammeDetails> getAllProgrammeDetails()
        {
            try
            {
                List<ProgrammeDetails> allProgrammeDetails = new List<ProgrammeDetails>();
                string command = "SELECT * FROM ProgrammeDetails;";
                SqlCommand sqlCommand = new SqlCommand(command, DBConnection.getInstance().Conn);

                DBConnection.getInstance().Conn.Open();
                using (SqlDataReader reader = sqlCommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int programmeID = reader.GetInt32(reader.GetOrdinal("ProgrammeID"));
                        string programmeName = reader.GetString(reader.GetOrdinal("Name"));

                        ProgrammeDetails pd = new ProgrammeDetails(programmeID, programmeName);
                        allProgrammeDetails.Add(pd);
                    }
                }
                return allProgrammeDetails;
            }
            catch (ArgumentOutOfRangeException aoorex)
            {
                return null;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                DBConnection.getInstance().Conn.Close();
            }
        }
        public static List <ProgrammeDetails> getAllProgrammeDetails()
        {
            try
            {
                List <ProgrammeDetails> allProgrammeDetails = new List <ProgrammeDetails>();
                string     command    = "SELECT * FROM ProgrammeDetails;";
                SqlCommand sqlCommand = new SqlCommand(command, DBConnection.getInstance().Conn);

                DBConnection.getInstance().Conn.Open();
                using (SqlDataReader reader = sqlCommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int    programmeID   = reader.GetInt32(reader.GetOrdinal("ProgrammeID"));
                        string programmeName = reader.GetString(reader.GetOrdinal("Name"));

                        ProgrammeDetails pd = new ProgrammeDetails(programmeID, programmeName);
                        allProgrammeDetails.Add(pd);
                    }
                }
                return(allProgrammeDetails);
            }
            catch (ArgumentOutOfRangeException aoorex)
            {
                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                DBConnection.getInstance().Conn.Close();
            }
        }