Bonjour,

Je développe actuellement un webservice, je souhaiterai récupérer les informations de plusieurs tables que je regrouperai dans une seule.
Beaucoup d'insertion se passent très bien (135 sur 150 environ) et pour le reste j'ai cette erreur :
Un objet qui autorise la valeur Null doit posséder une valeur.
Comment dois-je procéder pour la résoudre ?

Voici différentes méthodes qui pourraient être utilisées pour résoudre mon problème :

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
        public void updateQuery(string query)
        {
            try
            {
                if (maConnection == null || maConnection.State != ConnectionState.Open)
                {
                    this.Connect();
                }
                // Objet Command
                SqlCommand command = new SqlCommand(query, maConnection);
                // Execution
                command.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            //fermeture connexion
            this.Disconnect();
        }
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
        public string insertAgd(string rqtexcde, DateTime rqtsollimdte, bool wrktyppnt, int origcpyaddrincde, string origcpylocdsc, int ctcincde, int agdincde, int agdelapsedel, DateTime agdfromdte, DateTime agdtodte, DateTime agddonedte, string wrkdsc, int wrkstsincde, bool pdasendpnt, string typexcde)
        {
 
            return "INSERT INTO [SOMTEST].[dbo].[w_agdpec] " +
            "([RqtExCde] "+
            ",[RqtSolLimDte] "+
           ",[WrkTypPnt] "+
           ",[OrigCpyAddrIncde] "+
           ",[OrigCpyLocDsc] "+
           ",[CtcInCde] "+
           ",[AgdInCde] "+
           ",[AgdElapseDel] "+
           ",[AgdFromDte] "+
           ",[AgdToDte] "+
           ",[AgdDoneDte] "+
           ",[WrkDsc] "+
           ",[WrkStsInCde] "+
           ",[PDASendPnt] "+
           ",[TypExCde] "+
           ",[RqtPecInCde] "+
           ",[RqtPecFromDte] "+
           ",[RqtPecToDte] "+
           ",[WrkExCde] "+
           ",[RqtNatExCde]) "+
     "VALUES " +
           "('" + rqtexcde + "' " +
           ",'" + rqtsollimdte + "' " +
           "," + convertToBool(wrktyppnt) + " " +
           "," + origcpyaddrincde + " " +
           ",'" + origcpylocdsc + "' " +
           "," + ctcincde + " " +
           "," + agdincde + " " +
           "," + agdelapsedel + " " +
           ",'" + agdfromdte + "' " +
           ",'" + agdtodte + "' " +
           ",'" + agddonedte + "' "+
           ",'" + wrkdsc + "' "+
           "," + wrkstsincde + " "+
           "," + convertToBool(pdasendpnt) + " " +
           ",'"+typexcde+"' " +
           ",NULL" +
           ",NULL " +
           ",NULL " +
           ",NULL " +
           ",NULL)";
        }
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
public List<AGD> ListAGD(string d, int ctcincde)
        {
            Console.WriteLine("Contact : " + ctcincde.ToString());
            DataSet monDataSet = som.getQuery(r.getListeAGD(d, ctcincde));
            List<AGD> maliste = new List<AGD>();
 
            try
            {
                foreach (DataRow dr in monDataSet.Tables[0].Rows)
                {
                    AGD row = new AGD();
 
                    row.WrkTypPnt = (bool)dr["WrkTypPnt"];
                    row.OrigCpyAddrIncde = (int)dr["OrigCpyAddrIncde"];
                    row.WrkDsc = dr["WrkDsc"].ToString();
                    row.OrigCpyLocDsc = dr["OrigCpyLocDsc"].ToString();
                    row.AgdElapseDel = (int)dr["AgdElapseDel"];
                    row.AgdFromDte = (DateTime)dr["AgdFromDte"];
                    row.AgdToDte = (DateTime)dr["AgdToDte"];
                    row.PDASendPnt1 = (bool)dr["PDASendPnt"];
                    row.AgdInCde = (int)dr["AgdInCde"];
                    row.WrkStsInCde = Convert.ToInt32(dr["WrkStsInCde"]);
                    row.RqtExCde = dr["RqtExCde"].ToString();
                    row.CtcInCde = (int)dr["CtcInCde"];
 
                    try
                    {
                        row.RqtSolLimDte = (DateTime)dr["RqtSolLimDte"];
                        row.AgdDoneDte = (DateTime)dr["AgdDoneDte"];
                    }
                    catch
                    { }
 
                    maliste.Add(row);
                    Console.WriteLine(row.ToString());
                    somtest.updateQuery(r.insertAgd(row.RqtExCde, (DateTime)row.RqtSolLimDte, (bool)row.WrkTypPnt, row.OrigCpyAddrIncde, row.OrigCpyLocDsc, row.CtcInCde, row.AgdInCde, row.AgdElapseDel, (DateTime)row.AgdFromDte, (DateTime)row.AgdToDte, (DateTime)row.AgdDoneDte, row.WrkDsc, row.WrkStsInCde, (bool)row.PDASendPnt1, row.TypExCde));
                }
 
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
 
            return maliste;
        }
Merci d'avance pour votre aide