Exemplo n.º 1
0
        }//fin constructeur 

        //getStudent
        public Etudiant getEtudiant(int IdEtudiant)
        {
            var select = "SELECT etudiant.IdEtudiant, etudiant.Erasmus, etudiant.DernierDiplomeObtenu, etudiant.OrigineDiplome, etudiant.Natinoalite" + "\n"; 
            var from = "FROM student.ETUDIANT etudiant" + "\n";
            var where = "etudiant.IdEtudiant = {0}";

            var etudiant = new Etudiant();

            using (var dbConnection = new SqlConnection(StudentDbConnectionString))
            {
                dbConnection.Open();
                using (SqlCommand sqlCommand = dbConnection.CreateCommand())
                {
                    sqlCommand.CommandText = String.Format(select + from + where, IdEtudiant);

                    SqlDataReader reader = sqlCommand.ExecuteReader();
                    reader.Read();

                    int id = (int)reader["IdEtudiant"];
                    bool erasmus = (bool)reader["Erasmus"];
                    String dernierDiplomeObtenu = (String)reader["DernierDiplomeObtenu"];
                    String origineDiplome = (String)reader["OrigineDiplome"];
                    String nationalite = (String)reader["Nationalite"];

                    reader.Close();

                    etudiant.IdEtudiant = id;
                    etudiant.Erasmus = erasmus;
                    etudiant.DernierDiplomeObtenu = dernierDiplomeObtenu;
                    etudiant.OrigineDiplome = origineDiplome;
                    etudiant.Nationalite = nationalite;
                }

                dbConnection.Close();
            }
            return etudiant;
        }//fin getEtudiant
Exemplo n.º 2
0
        }//fin getEtudiant


        //getAllStudent
        public List<Etudiant> getAllEtudiants()
        {
            List<Etudiant> etudiants = null;

            using (var dbConnection = new SqlConnection(StudentDbConnectionString))
            {
                dbConnection.Open();
                using (SqlCommand sqlCommand = dbConnection.CreateCommand())
                {
                    sqlCommand.CommandText = "SELECT * FROM student.ETUDIANT";
                    SqlDataReader reader = sqlCommand.ExecuteReader();

                    etudiants = new List<Etudiant>();
                    while (reader.Read())
                    {
                        var etudiant = new Etudiant
                        {
                            IdEtudiant = (int)reader["IdEtudiant"],
                            Erasmus = (bool)reader["Erasmus"], 
                            DernierDiplomeObtenu = (String)reader["DernierDiplomeObtenu"],
                            OrigineDiplome = (String)reader["OrigineDiplome"],
                            Nationalite = (String)reader["Nationalite"]
                        };
                    }
                }
                dbConnection.Close();
            }
            return etudiants;
        }//fin getAllEtudiants