示例#1
0
        // Henter alle lyde fra databasen
        public IList <Lyd> GetAllLyd()
        {
            const string selectAllLyde = "Select * from Lydmaling";

            using (SqlConnection databaseConnection = new SqlConnection(ConnectionString))
            {
                databaseConnection.Open();
                using (SqlCommand selectCommand = new SqlCommand(selectAllLyde, databaseConnection))
                {
                    using (SqlDataReader reader = selectCommand.ExecuteReader())

                    {
                        List <Lyd> lydList = new List <Lyd>();
                        while (reader.Read())
                        {
                            int      id   = reader.GetInt32(0);
                            string   lyde = reader.GetString(1);
                            DateTime date = reader.GetDateTime(2);
                            Lyd      l1   = new Lyd()
                            {
                                Id   = id,
                                Lyde = lyde,
                                Date = date
                            };
                            lydList.Add(l1);
                        }
                        return(lydList);
                    }
                }
            }
        }
示例#2
0
        // Viser lyde og de steder lyd er sat til.
        public IList <Lyd> GetAllLydMedSted()
        {
            const string selectAllLyde = "SELECT Lydmaling.Lyde, Lydmaling.Dato, Steder.Sted FROM Lydmaling INNER JOIN Steder ON Lydmaling.[FK IdSted]=Steder.IdSted";

            using (SqlConnection databaseConnection = new SqlConnection(ConnectionString))
            {
                databaseConnection.Open();
                using (SqlCommand selectCommand = new SqlCommand(selectAllLyde, databaseConnection))
                {
                    using (SqlDataReader reader = selectCommand.ExecuteReader())

                    {
                        List <Lyd> lydList = new List <Lyd>();
                        while (reader.Read())
                        {
                            string   lyde = reader.GetString(0);
                            DateTime date = reader.GetDateTime(1);
                            string   sted = reader.GetString(2);
                            Lyd      l1   = new Lyd()
                            {
                                Lyde = lyde,
                                Date = date,
                                Sted = sted
                            };
                            lydList.Add(l1);
                        }
                        return(lydList);
                    }
                }
            }
        }