Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3036 connectés 

  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [C#] Utilisation correct de UpdateCommand [DataAdapter]

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[C#] Utilisation correct de UpdateCommand [DataAdapter]

n°627649
Mr yvele
yvele n'est plus.
Posté le 01-02-2004 à 12:55:14  profilanswer
 

Ben le truc c'est que je modifie mes donnés dans ma DataGrid, il n'update que la première ligne du tableau.. et apre sil me fait une belle erreur :
 

An unhandled exception of type 'System.Data.DBConcurrencyException' occurred in system.data.dll
Additional information: Concurrency violation: the UpdateCommand affected 0 records.


 :heink:  
 
en plus, l'orsque que je ne modifie qu'une seule ligne, il me l'applique bien à la bdd, mais il plante encore et toujours..
je ne sais pas pourquoi.. :/
 
 
 
 
le code :

Code :
  1. [...]
  2. //init
  3. private DataSet ds;
  4. private MySQLDataAdapter da;
  5. private MySQLConnection Connexion;
  6. [...]
  7. private void button1_Click(object sender, System.EventArgs e)
  8. {
  9. MySQLConnectionString ConnexionString = new MySQLConnectionString("test","root","" );
  10. Connexion = new MySQLConnection(ConnexionString.AsString);
  11. Connexion.Open();
  12. da = new MySQLDataAdapter("SELECT * FROM test",Connexion);
  13. da.TableMappings.Add("test","latable" );
  14. da.UpdateCommand  = new MySQLCommand("UPDATE test SET champ = @champ WHERE id = @id ",Connexion);
  15. da.UpdateCommand.Parameters.Add("@champ",System.Data.DbType.String,"champ" );
  16. da.UpdateCommand.Parameters.Add("@id",System.Data.DbType.String,"id" );
  17. da.InsertCommand = new MySQLCommand("INSERT INTO test (champ) VALUES (@champ) ",Connexion);
  18. da.InsertCommand.Parameters.Add("@champ",System.Data.DbType.String,"champ" );
  19. ds = new DataSet("lol" );
  20. da.Fill(ds);
  21. dataGrid1.SetDataBinding(ds,"Table" );
  22. }
  23. private void button2_Click(object sender, System.EventArgs e)
  24. {
  25. //////ERREUR ICI//////
  26. da.Update(ds,"Table" );
  27. //////////////////////
  28. ds.AcceptChanges();
  29. ds.Clear();
  30. da.Fill(ds,"Table" );
  31. }


---------------
yvele n'est plus.
mood
Publicité
Posté le 01-02-2004 à 12:55:14  profilanswer
 

n°627657
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 01-02-2004 à 13:06:06  profilanswer
 

personnellement, je ne me fais pas chier avec les UpdateCommand, InsertCommand, etc...
j'ai un objet OleDbCommand, que j'initialise avec ma connection comme ceci :

Code :
  1. command.Connection = myConnection; // command est mon OleDbCommand, et myConnection est un OleDbConnection (l'équivalent de ton SQLConnection je suppose)


 
ensuite je construis la requête dans une string, et enfin, quand je veux la lancer, je fais ceci :
 

Code :
  1. command.CommandText = requete; // requete est la chaine qui contient ma requete
  2. command.ExecuteNonQuery();


ça fonctionne, et je ne me fais pas chier avec les InsertCommand, UpdateCommand et tout [:sinclaire]


---------------
J'ai un string dans l'array (Paris Hilton)
n°627699
Mr yvele
yvele n'est plus.
Posté le 01-02-2004 à 14:16:38  profilanswer
 

ben tu construits manuellement tes requetes en fait..
alors que DataAdapter le fait automatiquement via UpdateCommand et compagnie.. [:sinclaire]


---------------
yvele n'est plus.

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [C#] Utilisation correct de UpdateCommand [DataAdapter]

 

Sujets relatifs
[C*UNIX]Utilisation du microphone !utilisation de prompt
utilisation d'une classe abstraiteUtilisation de dbExpress sous Delphi 7
[C] Utilisation de scandir..[VB6] Utilisation TreeView ?
[C++] Utilisation de Scheme au sein d'une application C++utilisation de generique pour un autre generique
l'utilisation des LINKS .. help !Problème : Utilisation sous Unix de fichiers écrits sous Windows
Plus de sujets relatifs à : [C#] Utilisation correct de UpdateCommand [DataAdapter]


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR