Microsoft KB Archive/325690

From BetaArchive Wiki

Article ID: 325690

Article Last Modified on 2/22/2007



APPLIES TO

  • Microsoft ADO.NET 1.1
  • Microsoft ADO.NET 1.0
  • Microsoft .NET Framework Class Libraries 1.0
  • Microsoft .NET Framework Class Libraries 1.1



This article was previously published under Q325690

SYMPTOMS

When you try to recursively navigate an XmlDataDocument that has been synchronized with a filled ADO.NET DataSet, all of the data is not returned.

CAUSE

A problem exists in the XmlDataDocument implementation of the RTM release of the Microsoft .NET Framework.

RESOLUTION

To work around this problem, access the InnerText property of the XmlDataDocument object before you recursively navigate it. You can also use the GetXml method of the DataSet object to load the XML representation of the DataSet data in an XmlDocument object and navigate it recursively.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This will be fixed in the next major version release of the .NET Framework.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new Microsoft Visual Basic .NET console application.
  2. Replace the code in Module1.vb with the following:NOTE: This sample requires that you have the Northwind sample database installed on a computer that is running Microsoft SQL Server. Modify the connection string to suit your environment.

    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Xml
    
    Module Module1
    
       Sub Main()
    
          Dim dsCustomers As New DataSet()
          dsCustomers.DataSetName = "CustomerData"
    
          ' Connect to the Northwind database on the local SQL Server.
          Dim sqlConn As String = "server=.;"
          sqlConn += "Integrated Security=SSPI;"
          sqlConn += "Initial Catalog=Northwind"
    
          ' Fill a DataSet with some customer data.
          Dim selectText As String
          selectText = "SELECT CustomerID, CompanyName"
          selectText += " City, Country FROM Customers WHERE CustomerID='ANATR'"
    
          Dim cmdCustomers As SqlDataAdapter = New SqlDataAdapter(selectText, sqlConn)
          cmdCustomers.Fill(dsCustomers, "Customers")
    
          ' Synchronize the DataSet with XmlDataDocument.
          Dim xmlDoc As New XmlDataDocument(dsCustomers)
    
          'PROBLEM: Try to access XmlDataDocument's content.
          Console.WriteLine("Output generated by recursively navigating the XmlDataDocument" & vbNewLine)
          renderNode(xmlDoc)
    
          'WORKAROUND: Accessing the XmlDataDocument's InnerText property using code 
          'identical to the following renders the data correctly.
          Dim dummy As String = xmlDoc.InnerText
          Console.WriteLine(vbNewLine & vbNewLine & "Output generated by recursively navigating" & _
             " the XmlDataDocument AFTER accessing its InnerText property" & vbNewLine)
          renderNode(xmlDoc)
          Console.ReadLine()
       End Sub
    
       Sub renderNode(ByVal inNode As XmlNode)
          Dim node As XmlNode
          For Each node In inNode.ChildNodes
             If node.NodeType = XmlNodeType.Element Then
                Console.WriteLine("Element Node: " & node.Name)
             End If
             If node.NodeType = XmlNodeType.Text Then
                Console.WriteLine("Text Node: " & node.Value)
             End If
             If node.HasChildNodes Then
                renderNode(node)
             End If
          Next
       End Sub
    
    End Module
                        
  3. Compile and run the application. The output is similar to the following:

    Output generated by recursively navigating the XmlDataDocument
    
    Element Node: CustomerData
    Element Node: Customers
    
    Output generated by recursively navigating the XmlDataDocument AFTER accessing its InnerText property
    
    Element Node: CustomerData
    Element Node: Customers
    Element Node: CustomerID
    Text Node: ANATR
    Element Node: City
    Text Node: Ana Trujillo Emparedados y helados
    Element Node: Country
    Text Node: Mexico
                        


REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

313649 INFO: Roadmap for XML Integration with ADO.NET


313651 INFO: Roadmap for XML in the .NET Framework


Keywords: kbbug kbpending KB325690