Salut à tous

Je voudrais modifier par une edition dans un DataGradView (que j'ai lier avec le DATASET : DS) toutes les colonnes y compris la clé principale.

en cliquant sur un bouton Update j'appel la Méthode suivante :

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
public void UpdateTable(string nameTable)
        {
              //  con : ma connection OLE à un fichier Access 2003
             //   DS : dataSet
             //   DAdp : Dataadapter
            //   nameTable : nom de ma table
 
 
 
               OleDbCommand comdUPDATE;
 
            string CommandText = "UPDATE " + nameTable + " SET IDObj=@IDObj ,NameParent=@NameParent,TypeObj=@TypeObj WHERE IDObj=@IDObj";
 
            comdUPDATE=DAdp.UpdateCommand = new OleDbCommand(CommandText, con);
 
            // IDObj : clé principale
            comdUPDATE.Parameters.Add(new OleDbParameter("@IDObj", OleDbType.VarChar, 50));
            comdUPDATE.Parameters.Add(new OleDbParameter("@NameParent", OleDbType.VarChar, 50));
            comdUPDATE.Parameters.Add(new OleDbParameter("@TypeObj", OleDbType.VarChar, 50));
 
            comdUPDATE.Parameters["@IDObj"].SourceVersion= DataRowVersion.Original; //!!!
            comdUPDATE.Parameters["@NameParent"].SourceVersion= DataRowVersion.Current;
            comdUPDATE.Parameters["@TypeObj"].SourceVersion= DataRowVersion.Current;
 
            comdUPDATE.Parameters["@IDObj"].SourceColumn = "IDObj";
            comdUPDATE.Parameters["@NameParent"].SourceColumn = "NameParent";
            comdUPDATE.Parameters["@TypeObj"].SourceColumn = "TypeObj";
 
            DataSet modifiedDS = DS.GetChanges(DataRowState.Modified);
 
 
            try
            {
                con.Open();
                DAdp.Update(modifiedDS.Tables[nameTable]);
                DS.Clear();
                DAdp.Fill(DS, nameTable);
                con.Close();
 
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
 
            }
            finally { con.Close(); }
 
		}
L'exeption : Concurrency violation : the update command affected 0 of the expected 1 records