Salut, en fait dans mon application je fais une requête sur un serveur MySQL.
Tout fonctionne bien, mais j'ai fait une petite remarque sur une variable qui garde à un certain moment la valeur de la précédente requête.
Je m'explique pour un test j'effectue un critère de sélection sur la date:
Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
select * from message where (DateMsg >= '2012-04-03' and DateMsg <= '2012-04-06');
j'ai un résultat d'affichage de 187 élément vérifiant cette clause. => OK c'est vrai.

Et voici un des événèment qui ne vérifie pas cette clause mais qui affiche le même résultat que la précende requête
Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
select * from message where (DateMsg >= '2012-04-05' and DateMsg <= '2012-04-06');
Cette requête devrait me renvoyer 0 éléments mais elle me renvoie toujours 187 éléments. => Faux
Sur mon serveur MySQL je refais ces galipettes, il ne se passe aucun problème.

Je vous donne mon code pour une analyse et essayer de trouver ensemble d'où vient le problème et le corriger.
Merci

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Public Sub BD_Recherche(ByVal lstview As ListView)
        WaitBar.ProgressBar1.Minimum = 0
        Dim i As Integer
        Dim myCommand1 As New MySqlCommand
        Dim MyAdapter1 As New MySqlDataAdapter
        Dim myDataTable1 As New DataTable
        Dim strQuery1 As String
        Dim strCountQuery1 As String
        Dim cResulat1 As Integer = 0
 
        Try
 
            If Form1.CmbExpediteur.Text = "ALL" And Form1.CmbStatut.Text = "ALL" Then
                strQuery1 = "select * from message where DateMsg >='" & Form1.DtpDebut.Text & "' and DateMsg <='" & Form1.DtpFin.Text & "';"
                strCountQuery1 = "select count(*) from message where DateMsg >='" & Form1.DtpDebut.Text & "' and DateMsg <='" & Form1.DtpFin.Text & "';"
 
            ElseIf Form1.CmbExpediteur.Text = "ALL" Then
                strQuery1 = "select * from message where DateMsg <='" & Form1.DtpFin.Text & "' and DateMsg >='" & Form1.DtpDebut.Text _
                & "' and DLR='" & Form1.CmbStatut.Text & "';"
                strCountQuery1 = "select count(*) from message where DateMsg <='" & Form1.DtpFin.Text & "' and DateMsg >='" & Form1.DtpDebut.Text _
               & "' and DLR='" & Form1.CmbStatut.Text & "';"
            ElseIf Form1.CmbStatut.Text = "ALL" Then
                strQuery1 = "select * from message where DateMsg <='" & Form1.DtpFin.Text & "' and DateMsg >='" & Form1.DtpDebut.Text _
                & "' and Expediteur='" & Form1.CmbExpediteur.Text & "';"
                strCountQuery1 = "select count(*) from message where DateMsg <='" & Form1.DtpFin.Text & "' and DateMsg >='" & Form1.DtpDebut.Text _
               & "' and Expediteur='" & Form1.CmbExpediteur.Text & "';"
            Else
                strQuery1 = "select * from message where DateMsg <='" & Form1.DtpFin.Text & "' and DateMsg >='" & Form1.DtpDebut.Text _
                & "' and Expediteur='" & Form1.CmbExpediteur.Text & "' and DLR='" & Form1.CmbStatut.Text & "';"
                strCountQuery1 = "select count(*) from message where DateMsg <='" & Form1.DtpFin.Text & "' and DateMsg >='" & Form1.DtpDebut.Text _
               & "' and Expediteur='" & Form1.CmbExpediteur.Text & "' and DLR='" & Form1.CmbStatut.Text & "';"
            End If
 
            myCommand1.Connection = conexion
            myCommand1.CommandText = strQuery1
            MyAdapter1.SelectCommand = myCommand1
            Dim CountQuery1 As New MySqlCommand(strCountQuery1, conexion)
            cResulat1 = CountQuery1.ExecuteScalar
            WaitBar.ProgressBar1.Maximum = cResulat1
 
            Dim myLine As ListViewItem
            Dim j As Double = 0
            MyAdapter1.Fill(myDataTable1)
 
            If cResulat1 > 0 Then 
 
'cResultat est la variable qui me retourne la valeur du compte que je fait avec CountQuery1.ExecuteScalar
 
                For i = 0 To myDataTable1.Rows.Count - 1
                    WaitBar.Show()
                    WaitBar.Refresh()
                    myLine = lstview.Items.Insert(0, myDataTable1.Rows(i)("DateMsg"))
                    myLine.SubItems.AddRange(New String() {myDataTable1.Rows(i)("HeureMsg").ToString, "SMS", myDataTable1.Rows(i)("FID"), myDataTable1.Rows(i)("Expediteur"), _
                   myDataTable1.Rows(i)("Destinataire"), myDataTable1.Rows(i)("Taille"), myDataTable1.Rows(i)("DLR")})
                    WaitBar.ProgressBar1.Value = i
                    Thread.Sleep(10)
                Next i
                WaitBar.Close()
            Else
                MsgBox("Aucun enregistrement trouvé !", MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub