运行时RDLC报告更新

时间:2016-05-16 15:17:40

标签: c# xml vb.net report rdlc

我想通过在vb.net中读取xml来更新运行时的rdlc报告。 我的报告如下:

<?xml version="1.0" encoding="utf-8"?>
<Report ....
<DataSources>
....
</DataSources>
<DataSets>
<DataSet Name="DS_MAIN">
<Fields>
<Field Name="Value3">
      <DataField>Value3</DataField>
      <rd:TypeName>System.String</rd:TypeName>
</Field>

和我一样用来访问这个节点

Dim MyXMLNode As Xml.XmlNode = MyXML.SelectSingleNode("/Report/DataSet[@Name='DS_MAIN']/Fields/Field[@Name='Value3']/DataField")

但我的MyXMLNode不会得到任何价值。 请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

尝试XML Linq

Imports System.Xml
Imports System.Xml.Linq
Module Module1

    Const FILENAME As String = "c:\temp\test.xml"
    Sub Main()


        Dim doc As XDocument = XDocument.Load(FILENAME)
        Dim root As XElement = doc.FirstNode
        Dim ns = root.Name.Namespace
        Dim fields = doc.Descendants(ns + "Field").Select(Function(x) New With { _
            .name = x.Attribute("Name").Value, _
            .datafield = x.Element(ns + "DataField").Value, _
            .typeName = x.Descendants().Where(Function(y) y.Name.LocalName = "TypeName").Select(Function(z) z.Value).FirstOrDefault() _
       }).ToList()
    End Sub

End Module