Bonjour,

J'aimerais savoir comment ajouter des données à un fichier XML provenant d'une structure XSD. Mon problème c'est que mon fichier XSD contient plusieurs niveau. Lorsque j'assigne mon datatable à mon dataset j'obtient l'erreur suivante...

Cannot add a column named 'COD_PRFSN': a nested table with the same name already belongs to this DataTable.
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Public Sub ExportXMLFile()

Dim dsMaster As New DataSet
dsMaster.Prefix = "ECHG_ORDRE_PROF"

dsMaster.ReadXmlSchema("C:\RAMQ.xsd")


'Section 0
dsMaster = PrepXmlSection(dsMaster, "ECHG_ORDRE_PROF", "SP_SEFE_Template_RAMQXMLS00_ENTET")

'Section 1
dsMaster = PrepXmlSection(dsMaster, "MBR_ORDRE", "SP_SEFE_Template_RAMQXMLS01_MBR")

'Section 2
dsMaster = PrepXmlSection(dsMaster, "INFO_GENRL_INTVN", "SP_SEFE_Template_RAMQXMLS02_INFO_GENRL_INTVN")


  dsMaster.WriteXml("C:\RAMQ.xml")

End Sub




Public Function PrepXmlSection(ByVal _dsMaster As DataSet, ByVal _TableName As String, ByVal _SPName As String) As DataSet

    'Create the datatable 
    Dim DataTable As New DataTable
    DataTable.TableName = _TableName ' this name will be use as a tag in the XML FIle

    'Cretate the dataAdapter
    Dim DataAdapter As New SqlDataAdapter

    'Create the SqlCommand
    Dim cmd As New SqlCommand
    cmd.Connection = oCOn
    cmd.CommandText = _SPName


    Dim _DR As SqlDataReader = Nothing
    If oCOn.State = ConnectionState.Closed Then
      oCOn.Open()
    End If

    _DR = cmd.ExecuteReader
    DataAdapter.SelectCommand = cmd

    _DR.Read()
    _dsMaster.Tables.Item(_TableName).Load(_DR)

    Return _dsMaster

End Function