Bonjour

Cela fait un bout de temps que j'essaye de comprendre une erreur dans une commande update

J'ai deja verifié 100 fois ma commandes et mes parametres sans comprendre

Question
1- Peut on definir plus de parametre que ceux que la commande doit utiliser ?
2- Il y a-t-il un truc pour comprendre plus facilement ce qui se passe ?


Merci aux experts qui peuvent m'aider

Voici l'erreur

{System.Data.SqlClient.SqlException: The parameterized query '(@HRK nvarchar(10),@HRKreel nvarchar(4000),@imei nvarchar(15),@p' expects the parameter '@dateVerif', which was not supplied.
un truc louche c'est
@HRKreel nvarchar(4000),
Car c'est défini comme nvarchar(16) dans la db
Et ca vaut "" dans la classe


Voici la commande
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
    private bool UpdateToDB()
    {
      SqlCommand MyCmd = new SqlCommand();
 
      string strSQL = "UPDATE PAPreprise SET "
                    + " HRK=@HRK, "
                    + " HRKreel=@HRKreel, "
                    + " imei=@imei, "
                    + " prixreprise=@prixreprise, "
                    + " prixreel=@prixreel, "
                    + " prix_hs=@prix_hs, "
                    + " prix_occasion=@prix_occasion, "
                    + " dateReprise=@dateReprise, "
                    + " dateImport=@dateImport, "
                    + " dateVerif=@dateVerif, "
                    + " etatreprise= @etatreprise, "
                    + " etatreel=@etatreel, "
                    + " refinternal=@refinternal, "
                    + " refclient=@refclient, "
                    + " srcFile=@srcFile, "
                    + " outFile=@outFile, "
                    + " outDate=@outDate "
                    + " WHERE ID={0}";
 
      MyCmd.CommandText = string.Format(strSQL,this.ID);
      AddParams(MyCmd);
      return Query.NonQueryCmd(MyCmd);
Voici l'ajout de parametres
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
    // *********************************************************************************
    private void AddParams(SqlCommand MyCmd)
    {
      MyCmd.Parameters.AddWithValue("@HRK", this.HRK);
      MyCmd.Parameters.AddWithValue("@HRKreel", this.HRKreel);
      MyCmd.Parameters.AddWithValue("@imei", this.imei);
      MyCmd.Parameters.AddWithValue("@prixreprise", this.prixReprise);
      MyCmd.Parameters.AddWithValue("@prixreel", this.prixReel);
      MyCmd.Parameters.AddWithValue("@prix_hs", this.prix_hs);
      MyCmd.Parameters.AddWithValue("@prix_occasion", this.prix_occasion);
      MyCmd.Parameters.AddWithValue("@dateReprise", this.dateReprise);
      MyCmd.Parameters.AddWithValue("@dateImport", this.dateImport);
      MyCmd.Parameters.AddWithValue("@dateVerif", this.dateVerif);
      MyCmd.Parameters.AddWithValue("@etatReprise", this.etatReprise);
      MyCmd.Parameters.AddWithValue("@etatreel", this.etatReel);
      MyCmd.Parameters.AddWithValue("@refinternal", this.refInternal);
      MyCmd.Parameters.AddWithValue("@refclient", this.refClient);
      MyCmd.Parameters.AddWithValue("@srcFile", this.srcFile);
      MyCmd.Parameters.AddWithValue("@outFile", this.outFile);
      MyCmd.Parameters.AddWithValue("@outDate", this.outDate);
    }