bonjour,

je souhaiterais faire un SELECT conditionnel avec 3 conditions.

en 1er je sélectionne des élément d'une table.
en 2ème j'exécute un Test pour savoir si l'enregistrement existe dans la table
en 3ème s'il n'existe pas je l'enregistre dans la new table.

voici mon code :

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
 
    Public Sub selectAxeRUN()
 
        ObjetCommand.CommandText = "SELECT * FROM Axes WHERE ftp=No AND statut=" & Chr(34) & "New" & Chr(34) & ""
 
        Dim myREADERnoFTP As OleDbDataReader = ObjetCommand.ExecuteReader()
 
        Do While myREADERnoFTP.Read()
 
            ObjetCommand1.CommandText = "SELECT Nom_client, Num_client, Nom_axe FROM Axes1 WHERE ((Nom_client = @Nom_client) AND (Num_client = @Num_client) AND (Nom_axe = @Nom_axe));"
            ObjetCommand1.Parameters.Add("@Nom_client", OleDbType.VarChar).Value = myREADERnoFTP.Item(1).ToString()
            ObjetCommand1.Parameters.Add("@Num_client", OleDbType.VarChar).Value = myREADERnoFTP.Item(2).ToString()
            ObjetCommand1.Parameters.Add("@Nom_axe", OleDbType.VarChar).Value = myREADERnoFTP.Item(3).ToString()
 
            Dim resultat As String = ObjetCommand1.ExecuteScalar
 
            If resultat = Nothing Then
                ObjetCommand2.CommandText = " INSERT INTO [Axes1] ( Nom_client, Num_client, Nom_axe, FDC_mini, FDC_maxi, statut, ftp )  VALUES ( @Nom_client, @Num_client, @Nom_axe, @FDC_mini, @FDC_maxi, @statut, @ftp );"
                ObjetCommand2.Parameters.Add("@Nom_client", OleDbType.VarChar).Value = myREADERnoFTP.Item(1).ToString()
                ObjetCommand2.Parameters.Add("@Num_client", OleDbType.VarChar).Value = myREADERnoFTP.Item(2).ToString()
                ObjetCommand2.Parameters.Add("@Nom_client", OleDbType.VarChar).Value = myREADERnoFTP.Item(3).ToString()
                ObjetCommand2.Parameters.Add("@Num_client", OleDbType.VarChar).Value = myREADERnoFTP.Item(4).ToString()
                ObjetCommand2.Parameters.Add("@Nom_client", OleDbType.VarChar).Value = myREADERnoFTP.Item(5).ToString()
                ObjetCommand2.Parameters.Add("@Num_client", OleDbType.VarChar).Value = "AJ"
                ObjetCommand2.Parameters.Add("@Nom_client", OleDbType.Boolean).Value = True
 
                ObjetCommand2.ExecuteNonQuery()
 
            Else
 
            End If
            resultat = Nothing
        Loop
 
        myREADERnoFTP.Close()
 
        ObjetConnection.Close()
    End Sub
voici ma table :



Le problème c'est que lorsque je fais le
Code : Sélectionner tout - Visualiser dans une fenêtre à part
SELECT Nom_client, Num_client, Nom_axe FROM Axes1 WHERE ((Nom_client = @Nom_client) AND (Num_client = @Num_client) AND (Nom_axe = @Nom_axe));
A la lecture, étape 1, il détecte bien qu'il n'y a pas de champs identique. il passe a l'étape 2 enregistre dans la table étape 3.

puis lorsqu'il teste le 2ème élément il détecte qu'il existe ??? alors que ma condition est sur les 3 and pas que sur 1 seul, ma variable resultat = test
WHERE ((Nom_client = @Nom_client) AND (Num_client = @Num_client) AND (Nom_axe = @Nom_axe))
je ne pige pas ??

pouvez vous m'orienter merci