J'ai toujours une System.Data.DBConcurrencyException

alebib Messages postés 10 Date d'inscription mercredi 3 mars 2004 Statut Membre Dernière intervention 28 juillet 2005 - 28 juil. 2005 à 15:47
cs_69chris Messages postés 318 Date d'inscription jeudi 30 janvier 2003 Statut Membre Dernière intervention 30 décembre 2005 - 29 juil. 2005 à 14:47
Bonjour voici le code qui cause de sérieux problèmes:

Public Shared Sub Test(ByVal strConnFormat As String)
Dim connFormat As New OracleConnection(strConnFormat)
Dim dr As OracleDataReader
Dim da As New OracleDataAdapter("SELECT * FROM NOM", connFormat)
Dim ds As New DataSet
Dim cb As New OracleCommandBuilder(da)
Dim foundRows As DataRow
Dim oGini As New C_GINI

da.InsertCommand = cb.GetInsertCommand
da.UpdateCommand = cb.GetUpdateCommand
da.DeleteCommand = cb.GetDeleteCommand

da.Fill(ds, "NOM")

'GINI.
dr = oGini.Trouver_Ress_Gini

Dim compt As Integer

While dr.Read
ds.Tables("NOM").PrimaryKey() = New DataColumn() {ds.Tables("NOM").Columns("logon")}
foundRows = ds.Tables("NOM").Rows.Find(dr.Item("logonid").ToString)

If Not foundRows Is Nothing Then
foundRows("CR") = "9999"

Try
da.Update(ds, "NOM")
Catch ex As Exception
compt += 1
End Try
End If
End While

Console.Write(compt)

cb.Dispose()
ds.Dispose()
da.Dispose()
connFormat.Close()
connFormat.Dispose()
End Sub

Dans mon DR il y a 2837 record.

2770 lève une exception de type System.Data.DBConcurrencyException.
21 sont mise à jour.
46 n'existe pas et c'est normal.

Les 2770 records sont de même type que les 21 qui fonctionnent.
Je comprends vraiment pas ce qui se passe.

Merci de bien vouloir m'aider.

1 réponse

cs_69chris Messages postés 318 Date d'inscription jeudi 30 janvier 2003 Statut Membre Dernière intervention 30 décembre 2005 1
29 juil. 2005 à 14:47
Salut,



Déjà, je me pose une question sur cette ligne



ds.Tables("NOM").PrimaryKey() = New DataColumn() {ds.Tables("NOM").Columns("logon")}



Que fait-elle dans la boucle?



Ensuite tu fais appel à Update dans la boucle.
L'exception est levée si il n'y a aucun changement dans la table
(traduction perso de la doc). Ca me parait clair.... Fait l'update en
dehors de la boucle while.



Et en plus, tu peux ajouter un test pour savoir si la
table a été modifiée avant de tenter une mise à jour. Ca évitera
d'avoir l'exception si ton traitement ne fais rien.



Chris


N'oubliez pas de cloturer votre post.
0
Rejoignez-nous