Re-bonjour

Je retrouve de nouveau le même problème ( message: System.NullReferenceException*: 'La référence d'objet n'est pas définie à une instance d'un objet.')

Explcications:

J'ai un datagridview ( non lié a un dataset )

construction:
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
   DgSessions.RowCount = 99;
                  DgSessions.ColumnCount = 6;
                  DgSessions.BackgroundColor = Color.White;
                  DgSessions.AlternatingRowsDefaultCellStyle.BackColor = Color.LightCyan;
                  DgSessions.Dock = DockStyle.Fill;
                  DgSessions.RowHeadersVisible = false;
                  DgSessions.ScrollBars = ScrollBars.Vertical;
                  DgSessions.Columns[0].Name = "Utilisation";
                  DgSessions.Columns[1].Name = "Login";
                  DgSessions.Columns["Login"].Width = Colonne1;
                  DgSessions.Columns[2].Name = "Password";
                  DgSessions.Columns["Password"].Width = Colonne2;
                  DgSessions.Columns[3].Name = "Libre1";
                  DgSessions.Columns["Libre1"].Width = Colonne3;
                  DgSessions.Columns[4].Name = "Libre2";
                  DgSessions.Columns["Libre2"].Width = Colonne4;
                  DgSessions.Columns[5].Name = "IdClient";
                  DgSessions.Columns[5].Visible = false;
je remplis le datagridview avec des données
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
  for (int i = 0; i <= DSPersonalData.Tables["PersonalData"].Rows.Count - 1; i++)
                        {
                              DgSessions.Rows[i].Cells["IdClient"].Value = DSPersonalData.Tables["PersonalData"].Rows[i]["DT_IdClient"].ToString();
                              DgSessions.Rows[i].Cells["Utilisation"].Value = DSPersonalData.Tables["PersonalData"].Rows[i]["DT_Utilisation"].ToString().Trim();
                              DgSessions.Rows[i].Cells["Login"].Value = DSPersonalData.Tables["PersonalData"].Rows[i]["DT_Login"].ToString().Trim();
                              DgSessions.Rows[i].Cells["Password"].Value = MyEncrypter.DecrypteString(DSPersonalData.Tables["PersonalData"].Rows[i]["DT_Password"].ToString());
                              DgSessions.Rows[i].Cells["Libre1"].Value = DSPersonalData.Tables["PersonalData"].Rows[i]["DT_Libre1"].ToString().Trim();
                              DgSessions.Rows[i].Cells["Libre2"].Value = DSPersonalData.Tables["PersonalData"].Rows[i]["DT_Libre2"].ToString().Trim();
                        }
Je supprimes une donnée dans une cellule avec le backspace, je valides avec ENTER , lorsque je sauvegarde les données , je reçois l'erreur
la sauvegarde se fais comme suit:
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
if ((DgSessions.Rows[i].Cells["Utilisation"].Value.ToString().Trim() != ""))
                        {
                              string My_requete = "INSERT INTO PersonalData (DT_IdClient,DT_Utilisation,DT_Login,DT_Password,DT_Libre1,DT_Libre2,DT_ToDelete) VALUES (@IdClient, @Utilisation, @Login, @Password, @Libre1, @Libre2, @ToDelete)";
 
                              SqlCommand My_Commande = new SqlCommand(My_requete, My_ConnexionSQL);
 
                              My_Commande.Parameters.Add("@IdClient", SqlDbType.NVarChar, 65);
                              My_Commande.Parameters.Add("@Utilisation", SqlDbType.NVarChar, 150);
                              My_Commande.Parameters.Add("@Login", SqlDbType.NVarChar, 100);
                              My_Commande.Parameters.Add("@Password", SqlDbType.NVarChar, 500);
                              My_Commande.Parameters.Add("@Libre1", SqlDbType.NVarChar, 150);
                              My_Commande.Parameters.Add("@Libre2", SqlDbType.NVarChar, 150);
                              My_Commande.Parameters.Add("@ToDelete", SqlDbType.Bit);
 
                               if (DgSessions.CurrentRow.Cells["Libre2"].Value == DBNull.Value | DgSessions.CurrentRow.Cells["Libre2"].Value == null )
                                    DgSessions.CurrentRow.Cells["Libre2"].Value = "";
 
 
 
 
 
 
                                    My_Commande.Parameters["@IdClient"].Value = LblIdDCustomer.Text.Trim();
                              My_Commande.Parameters["@Utilisation"].Value = DgSessions.Rows[i].Cells["Utilisation"].Value.ToString().Trim();
                              My_Commande.Parameters["@Login"].Value = DgSessions.Rows[i].Cells["Login"].Value.ToString().Trim();
                              My_Commande.Parameters["@Password"].Value = MyEncrypter.EncrypteString(DgSessions.Rows[i].Cells["Password"].Value.ToString());
                              My_Commande.Parameters["@Libre1"].Value = DgSessions.Rows[i].Cells["Libre1"].Value.ToString().Trim();
                              My_Commande.Parameters["@Libre2"].Value = DgSessions.Rows[i].Cells["Libre2"].Value.ToString().Trim();
                              My_Commande.Parameters["@ToDelete"].Value = false;
 
 
 
                              try
                              {
                                    My_Commande.Connection.Open();
                                    My_Commande.ExecuteNonQuery();
                                    My_Commande.Connection.Close();
 
 
                              }
                              catch (Exception ex)
                              {
 
                                    MessageBox.Show(ex.Message.ToString());
                              }
                        }
Quelqu'un peut m'expliquer le problème ou le pourquoi