Пример #1
0
        public static Parametre Get(Int32 Identifiant)
        {
            Parametre parametre = new Parametre();

            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = select + " WHERE Identifiant = @Identifiant;";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Identifiant", Identifiant);

            //Execution

            try
            {
                connection.Open();

                SqlDataReader dataReader = commande.ExecuteReader();

                while (dataReader.Read())
                {
                    parametre.Identifiant = dataReader.GetInt32(0);
                    parametre.Identifiant = dataReader.GetInt32(0);
                    parametre.Nom = dataReader.GetString(1);
                    parametre.Valeur = dataReader.GetString(2);
                }

                dataReader.Close();

            }
            catch (Exception)
            {
                parametre = null;
            }
            finally
            {
                connection.Close();
            }
            return parametre;
        }
Пример #2
0
        public static Boolean Insert(Parametre parametre)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"INSERT INTO Parametre (" + champs + ") VALUES (@Nom,@Valeur);";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Nom", parametre.Nom);
            commande.Parameters.AddWithValue("Valeur", parametre.Valeur);
            //Execution
            try
            {
                connection.Open();
                commande.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
        }
Пример #3
0
        public static Boolean Update(Parametre parametre)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"UPDATE Parametre
                               SET Nom=@Nom,Valeur=@Valeur
                               WHERE Identifiant=@Identifiant ;";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Identifiant", parametre.Identifiant);
            commande.Parameters.AddWithValue("Nom", parametre.Nom);
            commande.Parameters.AddWithValue("Valeur", parametre.Valeur);

            //Execution
            try
            {
                connection.Open();
                commande.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
        }
Пример #4
0
        public static List<Parametre> List()
        {
            List<Parametre> listeParametre = new List<Parametre>();

            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = select + ";";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres

            //Execution
            try
            {
                connection.Open();

                SqlDataReader dataReader = commande.ExecuteReader();

                while (dataReader.Read())
                {
                    Parametre parametre = new Parametre();
                    parametre.Identifiant = dataReader.GetInt32(0);
                    parametre.Nom = dataReader.GetString(1);
                    parametre.Valeur = dataReader.GetString(2);
                    listeParametre.Add(parametre);
                }

                dataReader.Close();

            }
            catch (Exception)
            {
                listeParametre = null;
            }
            finally
            {
                connection.Close();
            }
            return listeParametre;
        }