Bonjour
Dans ce bout de code :
J'ai le problème suivant : la requête du premier With semble s'exécuter, mais retourne "0" en enregistrements affectés, alors qu'elle devrait en affecter 48 (j'ai vérifié et revérifié dans access directement...). La requête du 2eme With s'exécute correctement.
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 Try 'Ouvrir la connexion ObjetConnection.Open() 'Instancier un objet Commande ObjetCommand = New OleDb.OleDbCommand With ObjetConnection.CreateCommand() .CommandType = CommandType.Text .CommandText = "UPDATE [1_GCD1] INNER JOIN [1_GCD2] ON [1_GCD1].NPDV = [1_GCD2].NPDV SET [1_GCD1].X = [1_GCD1].X_1, [1_GCD1].Y = [1_GCD1].Y_1 WHERE (([1_GCD2].[GCD_ADDRESSCORE] Is Null) Or ([1_GCD1].[GCD_ADDRESSCORE]>=[1_GCD2].[GCD_ADDRESSCORE]))" '.ExecuteNonQuery() MsgBox(.ExecuteNonQuery(), MsgBoxStyle.Information) End With With ObjetConnection.CreateCommand() .CommandType = CommandType.Text .CommandText = "UPDATE [1_GCD1] INNER JOIN [1_GCD2] ON [1_GCD1].NPDV = [1_GCD2].NPDV SET [1_GCD1].X = [1_GCD2].X_1, [1_GCD1].Y = [1_GCD2].Y_1 WHERE (([1_GCD1].[GCD_ADDRESSCORE] Is Null) Or ([1_GCD2].[GCD_ADDRESSCORE]>[1_GCD1].[GCD_ADDRESSCORE]))" '.ExecuteNonQuery() MsgBox(.ExecuteNonQuery(), MsgBoxStyle.Information) End With 'Fermer la connexion ObjetConnection.Close() Catch ex As Exception MsgBox(ex, MsgBoxStyle.Exclamation) End Try
Quand je rajoute un With "bidon" (qui ne peut rien affecter car le WHERE est impossible à réaliser) avant les 2 With ci-dessus, par exemple ça :
alors les 2 With suivants (ceux cités tout en haut) s'exécutent correctement ! Un peu comme si l'objetconnection avait besoin d'une sorte d'initialisation bidon pour ensuite fonctionner correctement...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 With ObjetConnection.CreateCommand() .CommandType = CommandType.Text .CommandText = "UPDATE [1_GCD1] INNER JOIN [1_GCD2] ON [1_GCD1].NPDV = [1_GCD2].NPDV SET [1_GCD1].X = [1_GCD1].X_1, [1_GCD1].Y = [1_GCD1].Y_1 WHERE ([1_GCD2].[GCD_ADDRESSCORE] = 'CONDITION IMPOSSIBLE')" '.ExecuteNonQuery() MsgBox(.ExecuteNonQuery(), MsgBoxStyle.Information) End With
Avez-vous une piste ? Côté SQL j'ai tout testé dans Access directement les requêtes fonctionnent bien, le problème ne semble pas venir de là.
Merci de votre aide![]()
Partager