Kleidp
Messages postés124Date d'inscriptionjeudi 5 juin 2003StatutMembreDernière intervention10 février 2008
-
12 nov. 2007 à 23:24
cs_lawid
Messages postés9Date d'inscriptionmercredi 14 juillet 2004StatutMembreDernière intervention 5 août 2008
-
24 juin 2008 à 10:11
Bonsoir,
je vous expose mon problème:
Apres avoir ajouté une nouvelle ligne dans ma table grâce à un CurrencyManager, je fais un update grâce a un adapter.Update. Jusque là aucun soucis, la ligne se retrouve bien dans ma table access :
Là ou ca se complique, c'est si je veux faire une modification de cette ligne tout de suite après (sans recharger l'appli) :
cmClient.EndCurrentEdit();
adapterClient.Update(dataSet21.Client);
dataSet21.Client.AcceptChanges();
Il y a une "Violation d'accès concurrentiel ". arg..
Je récupère l'erreur avec un catch(DBConcurrencyException ex) et regarde la ligne qui tente d'être mise à jour (ex.Row) mais tout est normal, j'en suis certain (id a modifier, les valeurs des champs ...).
J'ai aussi tenté de suspendre la liaison (binding) du crrencyManager avant l'update, mais rien (Ce qu'on fait pas quant on est désespéré ...)
J'ai enlevé ma clef primaire, la relation de la table, toujours rien (alors là j'étais au bout :).
Si je recharge mon appli par contre tout fonctionne bien, alors en attendant, la solution que j'ai trouvé est de vider la table puis de la remplir dès que je fais un Update -_-
C'est une erreur qu'on retrouve sur les forums mais je n'ai vu aucune solution. Enfin il y a une première fois a tout ;)
Nb : j'ai le meme soucis avec le Delete forcément.
TheSaib
Messages postés2367Date d'inscriptionmardi 17 avril 2001StatutMembreDernière intervention26 décembre 200723 13 nov. 2007 à 02:01
Je n'y ai pas réfléchi mais je t'ai trouvé çà :
"If I understand everything correctly, here is a possible reason. You say you
insert new rows and then call Update.Does the database adjust any
autoincremented fields, or any other fields when it does the insert? If so,
then the problem is, that these changes do not get reflected in the DataSet.
So say you have a column A, that gets autoincremented. Initially, in your
DataSet it is null, when the row gets inserted into the database, the
database autoincrements it, and sets the new row's A value, to say 100. Your
DataSet still has a value of null. You make some changes to the row and
call Update. In the Update statement, it generates a WHERE clause, to make
sure it updates the right row. It is looking for A=null, but the database
has A=100 for that row. Thus, it has nothing to update.
If you do the Fill, then it gets updated in the DataSet to 100, you make
your modifications and Update again successfully, because now it is looking
for A=100, and it can find it."
cs_lawid
Messages postés9Date d'inscriptionmercredi 14 juillet 2004StatutMembreDernière intervention 5 août 2008 27 déc. 2007 à 12:45
Bonjour,
Es ce que réelement tu as resolu se probleme avec un Acceptchange()??
ce que je c si tu execute un acceptchange() avant un adapter.update(tableName)
tu n'auras rien a sauvegarder.
Revoie t'as solution et eclair moi
cs_fanatek
Messages postés1Date d'inscriptionvendredi 20 juin 2003StatutMembreDernière intervention19 juin 2008 19 juin 2008 à 14:37
J'avais le même problème et en effet en ajoutant un AcceptChanges sur le DataSet ça a résolu mon exception.
Bizarre quand même car je débute et j'ai appris les manipulations des dataset depuis ce cours http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson05.aspx dans lequel il ne parle pas de cet AcceptChanges();
Du coup son code :
// Update button was clicked
publicvoid btnUpdateClicked(object sender, EventArgs e)
{
// write changes back to DataBase
daCustomers.Update(dsCustomers, tableName);
}
devient
// Update button was clicked
publicvoid btnUpdateClicked(object sender, EventArgs e)
{
// write changes back to DataBase
dsCustomer.AcceptChanges();
daCustomers.Update(dsCustomers, tableName);
}
cs_lawid
Messages postés9Date d'inscriptionmercredi 14 juillet 2004StatutMembreDernière intervention 5 août 2008 24 juin 2008 à 10:04
bonjour, es ce que t'as resolu le pb???
voici sur koi je me suis basé pour le message que j'ai posté
MSDN
""Calling the [ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.data/html/26785ca9-b420-ff02-e83d-140fdc4761a7.htm AcceptChanges] method or [ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.data/html/e02d9dca-3f45-3d13-bc48-81776568cec1.htm AcceptChanges] method will commit all changes in the [ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.data/html/de5c6694-02a3-75b6-7643-4a4560f94e73.htm DataSet] or [ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.data/html/8a73ab8a-b5d2-531b-d030-ba555015a054.htm DataTable]. If either of these methods are called before the [ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.data/html/b45c1529-6e86-e0aa-4d3f-1253c9cd128f.htm Update] method is called, no changes will be committed when the [ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.data/html/b45c1529-6e86-e0aa-4d3f-1253c9cd128f.htm Update] method is called, unless further changes have been made since [ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.data/html/26785ca9-b420-ff02-e83d-140fdc4761a7.htm AcceptChanges] or [ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.data/html/e02d9dca-3f45-3d13-bc48-81776568cec1.htm AcceptChanges] was called.""
Essai de listé la liste des changement sur ton datatable avec la methode "getchange()"
cs_lawid
Messages postés9Date d'inscriptionmercredi 14 juillet 2004StatutMembreDernière intervention 5 août 2008 24 juin 2008 à 10:08
a propos n'oubly pas que la methode update return un "int", et si l' "adapter" ne recoie pas un message du moteur de la base de donné il generera une exception de violation d'acces
cs_lawid
Messages postés9Date d'inscriptionmercredi 14 juillet 2004StatutMembreDernière intervention 5 août 2008 24 juin 2008 à 10:11
from msdn
The [ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.data/html/f4dc4de3-e62b-53b6-fd0d-cac79261a99b.htm DataAdapter] examines the number of rows affected by the execution of each insert, update, or delete operation, and throws this exception if the number equals zero. This exception is generally caused by a concurrency violation.