Bonjour,

J'ai un petit soucis de programmation,

J'essaie de modifier des valeurs de structure grâce à la class Reflexion du .NET,

J'ai un premier module : A_VariableGlobale_GetDataFromBdd , où je déclare mes structures.

Ensuite j'ai une classe C_GetDataFromBDD, ou j'ai plusieur méthode:
Le Main ==> MainGetDataFromBDD() ,ou je lance mes 3 méthode de ma classe
La méthode GetNbLigneFromBDD() , où je retrouve le nombres de lignes pour chaques table de ma BDD
La méthode GetAllInfosFromBDD() , où je tente de récupéré par Reflexion les données de mes Tables

===> Et la ca bloque, quand je Test mes structures avec la méthode TestData() mes structures sont Nothing ...

Est ce que quelqu'un sait pourquoi j'arrive à implémenter mes structures et à mettre des valeurs dedans avec ma méthode GetAllInfosFromBDD() , mais après, lorsque je fait un test je n'ai plus rien dedans ?

Voici le 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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
Module A_VariableGlobale_GetDataFromBdd
    ''###################  DECLARATION DU NOMBRE DE LIGNE DE CHAQUE TABLES ###################'
    Public NbLigneIn_BSWA As Integer
    Public NbLigneIn_BSWN As Integer
    Public NbLigneIn_GITA As Integer
    Public NbLigneIn_GSPA As Integer
    Public NbLigneIn_HITN As Integer
    Public NbLigneIn_MITT As Integer
    Public NbLigneIn_NBEN As Integer
    Public NbLigneIn_NFRN As Integer
    Public NbLigneIn_NFRS As Integer
    Public NbLigneIn_NNLN As Integer
    Public NbLigneIn_NNWN As Integer
    Public NbLigneIn_TAUA As Integer
    Public NbLigneIn_TBEA As Integer
    Public NbLigneIn_TFIA As Integer
    Public NbLigneIn_TFRA As Integer
    Public NbLigneIn_TGEA As Integer
    Public NbLigneIn_TGEE As Integer
    Public NbLigneIn_TGEF As Integer
    Public NbLigneIn_TGRA As Integer
    Public NbLigneIn_TNZA As Integer
    Public NbLigneIn_TOMF As Integer
    Public NbLigneIn_TPOA As Integer
    ''## ==> Si vous avez new Batch ==> Recopiez une des variables précèdente et changer son nom
 
    '###################  DECLARATION DES STRUCTURE ###################'
    '----------------- Structure BSWA -----------------'
    Public Structure GETINFOSINBDD
        Dim GetId As Integer ' = 0
        Dim Flag As String '= 0
        Dim FirstEffectivité As String '= 0
        Dim EndEffectivité As String '= 0
        Dim FlagToImplement As String '= 0
        Dim Flag1BDB As String '= 0
    End Structure
    Public MyStruct_BSWA(0 To 4) As GETINFOSINBDD
    '----------------- Structure BSWN -----------------'
    Public MyStruct_BSWN() As GETINFOSINBDD
    '----------------- Structure GITA -----------------'
    Public MyStruct_GITA() As GETINFOSINBDD
    '----------------- Structure GSPA -----------------'
    Public MyStruct_GSPA() As GETINFOSINBDD
    '----------------- Structure HITN -----------------'
    Public MyStruct_HITN() As GETINFOSINBDD
    '----------------- Structure MITT -----------------'
    Public MyStruct_MITT() As GETINFOSINBDD
    '----------------- Structure NBEN -----------------'
    Public MyStruct_NBEN() As GETINFOSINBDD
    '----------------- Structure NFRN -----------------'
    Public MyStruct_NFRN() As GETINFOSINBDD
    '----------------- Structure NFRS -----------------'
    Public MyStruct_NFRS() As GETINFOSINBDD
    '----------------- Structure NNLN -----------------'
    Public MyStruct_NNLN() As GETINFOSINBDD
    '----------------- Structure NNWN -----------------'
    Public MyStruct_NNWN() As GETINFOSINBDD
    '----------------- Structure TAUA -----------------'
    Public MyStruct_TAUA() As GETINFOSINBDD
    '----------------- Structure TBEA -----------------'
    Public MyStruct_TBEA() As GETINFOSINBDD
    '----------------- Structure TFIA -----------------'
    Public MyStruct_TFIA() As GETINFOSINBDD
    '----------------- Structure TFRA -----------------'
    Public MyStruct_TFRA() As GETINFOSINBDD
    '----------------- Structure TGEA -----------------'
    Public MyStruct_TGEA() As GETINFOSINBDD
    '----------------- Structure TGEE -----------------'
    Public MyStruct_TGEE() As GETINFOSINBDD
    '----------------- Structure TGEF -----------------'
    Public MyStruct_TGEF() As GETINFOSINBDD
    '----------------- Structure TGRA -----------------'
    Public MyStruct_TGRA() As GETINFOSINBDD
    '----------------- Structure TNZA -----------------'
    Public MyStruct_TNZA() As GETINFOSINBDD
    '----------------- Structure TOMF -----------------'
    Public MyStruct_TOMF() As GETINFOSINBDD
    '----------------- Structure TPOA -----------------'
    Public MyStruct_TPOA() As GETINFOSINBDD
    '## ==> Si vous avez new Batch ==> Recopiez une des declaration précèdente et changer son nom
End Module
 
 
 
 
Public Class C_GetDataFromBDD
    Public MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data source=*****************\BDDV2.accdb")
    Public Mycommand As OleDbCommand = MyConnexion.CreateCommand()
    Public GetAllNbLigneBDDInTab As New Hashtable
 
 
 
 
    Public Sub MainGetDataFromBDD()
        GetNbLigneFromBDD()
        GetAllInfosFromBDD()
        TestData()
    End Sub
 
 
 
    Private Sub GetNbLigneFromBDD()
        'On se connecte à la BDD
        MyConnexion.Open()
        Dim GetVarNbLigne = GetType(A_VariableGlobale_GetDataFromBdd).GetFields
        For Each VarNbLigne As Object In GetVarNbLigne
            Dim NomVar = VarNbLigne.Name
            'Si c'est des NbLigne
            If Left(NomVar, 7) = "NbLigne" Then
                'on récupère le nom du batch
                Dim GetNameOfTheBatchForThisVarNbLigne = Right(NomVar, 4)
                '-----------------------------Récupération nb ligne dans la Table -------------------------------'
                Mycommand.CommandText = "SELECT COUNT(*) FROM " & GetNameOfTheBatchForThisVarNbLigne
                VarNbLigne.SetValue(VarNbLigne, Mycommand.ExecuteScalar())
                Dim GetValue = Mycommand.ExecuteScalar()
                GetAllNbLigneBDDInTab.Add(GetNameOfTheBatchForThisVarNbLigne, GetValue)
            End If
        Next
    End Sub
 
 
    Private Sub GetAllInfosFromBDD()
        Dim ctnbligne As Integer
        Dim GetVarStruct = GetType(A_VariableGlobale_GetDataFromBdd).GetFields
        Dim fields As Reflection.FieldInfo() = GetType(A_VariableGlobale_GetDataFromBdd).GetFields
        For Each field As Reflection.FieldInfo In fields
            If field.Name Like "MyStruct*" Then
                Dim MyStructArray As GETINFOSINBDD() = TryCast(field.GetValue(Nothing), GETINFOSINBDD())
                'on recupêre le nom du flag
                Dim GetNameOfTheBatchForThisStruct = Right(field.Name, 4)
                'on recupère le nombre de ligne dans la table
                Dim GetNbLigne = GetAllNbLigneBDDInTab.Item(GetNameOfTheBatchForThisStruct)
                'on initialise le tableau pour pouvoir implementer les donnée
                ReDim MyStructArray(0 To GetNbLigne)
 
                'On récupère les infos
                Mycommand.CommandText = "SELECT * FROM " & GetNameOfTheBatchForThisStruct
                Dim InfosInStruct As OleDbDataReader = Mycommand.ExecuteReader()
                Do While InfosInStruct.Read()
                    ctnbligne = ctnbligne + 1
                    MyStructArray(ctnbligne).GetId = InfosInStruct.GetValue(0)
                    MyStructArray(ctnbligne).Flag = InfosInStruct.GetValue(1)
                    MyStructArray(ctnbligne).FirstEffectivité = InfosInStruct.GetValue(2)
                    MyStructArray(ctnbligne).EndEffectivité = InfosInStruct.GetValue(3)
                    MyStructArray(ctnbligne).FlagToImplement = InfosInStruct.GetValue(4)
                    MyStructArray(ctnbligne).Flag1BDB = InfosInStruct.GetValue(5)
                Loop
 
                ctnbligne = 0
                InfosInStruct.Close()
            End If
        Next
 
        'On ferme la BDD
        MyConnexion.Close()
    End Sub
 
 
    Private Sub TestData()
        Dim tesqtset = MyStruct_BSWA
 
 
        Dim zertzer = MyStruct_BSWN(2).Flag
    End Sub
End Class

Merci pour vos réponses.
Cyril