Beispiel #1
0
        public Adherent Adh(int id)
        {


            Adherent Adh = null;



            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                connection.Open();
                string query = "Select * from adherent where id_adh=@id";


                //Create Command
                MySqlCommand cmd = new MySqlCommand(query, connection);

                cmd.Parameters.AddWithValue("@id", id);

                //Create a data reader and Execute the command
                using (MySqlDataReader dataReader = cmd.ExecuteReader())
                {

                    //Read the data and store them in the list
                    while (dataReader.Read())
                    {
                        Adh = new Adherent();
                        Adh.setId(dataReader["id_adh"] != DBNull.Value ? (int)dataReader["id_adh"] : 0);
                        Adh.setNom((string)dataReader["nom_adh"]);
                        Adh.setprenom((string)dataReader["prenom_adh"]);
                        Adh.setadr((string)dataReader["adresse_adh"]);
                        Adh.setville((string)dataReader["ville_adh"]);
                        Adh.setcp(dataReader["cp_adh"] != DBNull.Value ? (int)dataReader["cp_adh"] : 0);
                        Adh.setmail((string)dataReader["mail_adh"]);
                        Adh.settel((string)dataReader["tel_adh"]);


                    }

                }
                return Adh;
            }
        }