Bonjour à tous,

Je souhaiterai faire en sorte que mes résultats de requête s'affichent sur plusieurs pages lors de la génération de mon PDF. Pour le moment mes résultats ne s'affichent que sur une seule page, et sont donc limitées en nombre.
Voici mon code:

Voici ma requête initiale:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
Obj_Command = New OleDbCommand()
        'initialiser l'objet Command
        Obj_Command.Connection() = laConnection
        Obj_Command.CommandText = "SELECT TOP 80 LE_ID, LE_DATE, LE_COMPTE, LE_LIBELLE, LE_MONTANT, LE_NATURE, LE_JOURNAL FROM(LIGNE_ECRITURE) WHERE LE_DATE BETWEEN #" + Format("dd/mm/yyyy", dtp_deb.Text) + "# AND #" + Format("dd/mm/yyyy", dtp_fin.Text) + "# AND LE_JOURNAL = 'JDV' AND (LE_COMPTE LIKE '411%' OR LE_COMPTE='44571000' OR LE_COMPTE='70600000' OR LE_COMPTE='70700000' ) AND LE_LETTRAGE = false ORDER BY LE_DATE DESC, LE_ID DESC"
        Obj_Reader = Obj_Command.ExecuteReader()
Ensuite je fais la mise en page de mes résultats:
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
        While Obj_Reader.Read()
            If Obj_Reader.GetValue(5).ToString() = "Débit" Then
                ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 578, ypos + pos_y)
            ElseIf Obj_Reader.GetValue(5).ToString() = "Crédit" Then
                ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 672, ypos + pos_y)
            End If
            pos_y = pos_y + 20
        End While
Et voici ma partie de code pour la création d'une deuxième feuille (et plus si nécessaire) :
1: Je récupérer le nombre de lignes à l'aide d'une deuxième requête:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
       'Instancier un objet Commande
        Obj_Command2 = New OleDbCommand()
        'initialiser l'objet Command
        Obj_Command2.Connection() = laConnection
        'requête pour affichage des articles
        Obj_Command2.CommandText = "SELECT COUNT(LIGNE_ECRITURE.LE_ID) AS Nbr FROM (LIGNE_ECRITURE) "
        Obj_Reader2 = Obj_Command2.ExecuteReader()
        Obj_Reader2.Read()
 
        Dim vente As String
        vente = Obj_Reader2.Item("LE_ID").ToString
2: je convertis mon String en Integer:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
        Dim vente1 As Integer
        vente1 = Integer.Parse(vente)
        Obj_Reader2.Close()
 
 
        If (vente1 > 40) Then
            Dim compteur As Integer = 0
3: J'utilise un Select Case pour déterminer le nombre de pages nécessaires:
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
66
67
68
69
70
71
72
73
74
75
            Select Case NumPage
                Case 1
                    While Obj_Reader.Read() And compteur <= 40
                        Dim ens As String = Obj_Reader.Item("LE_ID").ToString
                        If (ens <> "") Then
                            compteur = compteur + 1
                            If Obj_Reader.GetValue(5).ToString() = "Débit" Then
                                ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                                ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                                ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                                ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                                ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 578, ypos + pos_y)
                            ElseIf Obj_Reader.GetValue(5).ToString() = "Crédit" Then
                                ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                                ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                                ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                                ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                                ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 672, ypos + pos_y)
                            End If
                            pos_y = pos_y + 20
                        End If
 
                    End While
                    ev.HasMorePages = True
                    NumPage += 1
                    Obj_Reader.Close()
                Case 2
                    While Obj_Reader.Read()
                        Dim ens As String = Obj_Reader.Item("LE_ID").ToString
                        If (ens <> "") Then
                            compteur = compteur + 1
                            If (compteur > 40) Then
                                If Obj_Reader.GetValue(5).ToString() = "Débit" Then
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                                    ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                                    ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 578, ypos + pos_y)
                                ElseIf Obj_Reader.GetValue(5).ToString() = "Crédit" Then
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                                    ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                                    ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 672, ypos + pos_y)
                                End If
                                pos_y = pos_y + 20
                            End If
                        End If
                    End While
                    ev.HasMorePages = False
                    NumPage = 1
            End Select
        Else 'si nombre de ligne < 41 
            While Obj_Reader.Read()
                Dim ens As String = Obj_Reader.Item("LE_ID").ToString
                If (ens <> "") Then
                    If Obj_Reader.GetValue(5).ToString() = "Débit" Then
                        ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                        ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                        ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                        ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                        ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 578, ypos + pos_y)
                    ElseIf Obj_Reader.GetValue(5).ToString() = "Crédit" Then
                        ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                        ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                        ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                        ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                        ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 672, ypos + pos_y)
                    End If
                    pos_y = pos_y + 20
                End If
            End While
        End If
        Obj_Reader.Close()
    End Sub
Je reste dans une impasse et ne trouve pas comment avoir un affichage correct sur plusieurs pages. Je m'en remets à vous et votre savoir,
Cordialement,

Ludwig Robert