Bonjour,

J'approfondie mes connaissances en c# grâce au tutoriel suivant

J'en suis au début et je rencontre un problème en ce qui concerne le ConfigurationManager: lorsque je débug l'application la classe me renvoie null.
Après avoir lu de nombreux thread tuto et autres, je n'ai rien trouvé qui puisse ressembler à mon problème. J'ai bien
- ajouter la référence
- le namespace.

La classe est bien reconnu mais n'arrive pas à récupérer les valeurs de mon fichiers config ci contre :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name ="simulateurPaie"
         connectionString="Data Source=.\MSSMLBIZ;
                           AttachDbFilename=D:\dbpam.mdf;
                           Initial Catalog=dbpam;
                           Integrated Security=True;
                           Connect Timeout=30;
                           User Instance=True"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="employe"
         value="SELECT EMPLOYES.NOM_EMPLOYE, EMPLOYES.PRENOM_EMPLOYE, EMPLOYES.ADRESSE_EMPLOYE, EMPLOYES.VILLE_EMPLOYE, 
                       EMPLOYES.CODEPOSTAL, EMPLOYES.INDICE, INDEMNITES.BASEHEURE, INDEMNITES.ENTRETIENJOUR, INDEMNITES.REPASJOUR, 
                       INDEMNITES.INDEMNITECP
                FROM   EMPLOYES INNER JOIN
                       INDEMNITES ON EMPLOYES.INDICE = INDEMNITES.INDICE
                WHERE  SS=@SS"/>
    <add key="allEmployes"
         value="SELECT PRENOM_EMPLOYE,NOM_EMPLOYE,SS_EMPLOYE 
                from   EMPLOYES"/>
    <add key="cotisations"
         value="SELECT CSGRDS,CSGD,SECU,RETRAITE 
                from   COTISATIONS"/>
  </appSettings>
</configuration>
Et voici mon .cs:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
using System;
using System.IO;
using System.Configuration;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
 
namespace SimupaieVersion1_Form
{
    public partial class Form1 : Form
    {
        //données du formulaire
        public string cConnexion=null;
        public string employe;
        public string allEmployes;
        public string cotisations;
        public SqlConnection con;
 
        private SqlCommand command;
 
        public Form1()
        {
            InitializeComponent();
 
            //récupération de la configuration
            try
            {
                //recuperation des données du fichier de configuration                
                cConnexion = ConfigurationManager.ConnectionStrings[0].ConnectionString;
 
 
                employe = ConfigurationManager.AppSettings.Get("employe");
                Console.WriteLine("employé: " +employe);
                allEmployes = ConfigurationManager.AppSettings.Get("allEmployes");
                cotisations = ConfigurationManager.AppSettings.Get("cotisations");
 
            }
            catch (SqlException SQL)
            {
                commentaire.Text = "Erreur dans la configuration de [SimuPaie.config] " + SQL.Message;
            }
Je ne sais plus où chercher!!!
Quelqu'un saurait il d'où le problème peut venir??????
Il arrive à récupérer le connectionString mais ya rien à faire pour appsettings...

Merci d'avance