Пример #1
0
        public static Meassurement Delete(int id)
        {
            Meassurement m = Get(id);

            try
            {
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = $"delete * from Meassurement where id = {id}";
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
            }

            return(m);
        }
Пример #2
0
        public static Meassurement Add(Meassurement m)
        {
            try
            {
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = $@"insert into Meassurement 
                        (Pressure, Humidity, Temperatur, TimeStamp) VALUES 
                ({m.Pressure}, {m.Humidity},{m.Temperatur}, {m.TimeStamp})"; // '{m.navn}' hvis den har en string
                    cmd.ExecuteNonQuery();                                   // En execute der ikke returnerer noget
                }
            }
            catch (Exception e)
            {
            }

            return(m);
        }
Пример #3
0
        public static List <Meassurement> GetAll()
        {
            List <Meassurement> mList = new List <Meassurement>();

            try
            {
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = "select * from Meassurement";
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Meassurement m = new Meassurement();
                            m.Id = reader.GetInt32(0);
                            if (!reader.IsDBNull(1)) // hvis den kan være null benyt if statement
                            {
                                m.Pressure = reader.GetDecimal(1);
                            }
                            if (!reader.IsDBNull(2)) // hvis den kan være null benyt if statement
                            {
                                m.Humidity = reader.GetDecimal(2);
                            }
                            if (!reader.IsDBNull(3)) // hvis den kan være null benyt if statement
                            {
                                m.Temperatur = reader.GetDecimal(3);
                            }
                            if (!reader.IsDBNull(4)) // hvis den kan være null benyt if statement
                            {
                                m.TimeStamp = reader.GetDateTime(4);
                            }


                            mList.Add(m);
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(mList);
        }