Exemple #1
0
        public Gamme Get(int id)
        {
            Gamme g = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = @"SELECT Identifiant, Libelle FROM Gamme
                  WHERE Identifiant = @identifiant";

                command.Parameters.AddWithValue("@identifiant", id);

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    reader.Read();

                    g = new Gamme();

                    g.Identifiant = (int)reader["Identifiant"];

                    g.Libelle = reader["Libelle"] is System.DBNull ? null : reader["Libelle"].ToString();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return(g);
        }
Exemple #2
0
        public List <Gamme> GetAll()
        {
            List <Gamme> gammes = new List <Gamme>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = "SELECT Identifiant, Libelle FROM Gamme";

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        Gamme g = new Gamme();

                        g.Identifiant = (int)reader["Identifiant"];

                        g.Libelle = reader["Libelle"] is System.DBNull ? null : reader["Libelle"].ToString();

                        gammes.Add(g);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return(gammes);
        }