Microsoft KB Archive/326599

From BetaArchive Wiki

Article ID: 326599

Article Last Modified on 9/24/2003



APPLIES TO

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



This article was previously published under Q326599

SYMPTOMS

If an XmlDataDocument object is bound to a DataSet object, and the DataSet data is changed, the XmlDataDocument does not fire NodeChanged events.

CAUSE

When the XmlDataDocument object is bound to a DataSet object, the XmlDataDocument does not contain nodes. Nodes are created when they are first accessed. Because the XmlDataDocument does not yet contain nodes, changes to the DataSet do not trigger NodeChanged events.

RESOLUTION

To work around this problem, you must access each and every node in the document tree. To do this, use the InnerText property of the XmlDataDocument object one time. When each node has been accessed (and, therefore, created) all events fire.

STATUS

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

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET. On the File menu, click New and then click Projects.
  2. Click Visual Basic Projects under Project Types, and then click Windows Application under Templates. By default, Form1.vb is created.
  3. Drag a DataGrid control (DataGrid1) and a Button control (Button1) from the toolbox to Form1.
  4. Import the following namespaces:

    Imports System.Xml
    Imports System.Data.SqlClient
                        
  5. Dim the following as a global variable:

     Dim WithEvents xmldoc As Xml.XmlDataDocument
                        
  6. Paste the following code in the Button1_click event:

     Try
        'Open a new connection to SQL Server database. 
        Dim cnNwind As New SqlConnection("data source=SqlServername;integrated security=SSPI;initial catalog=Northwind;")
        Dim daProducts As New SqlDataAdapter("Select * from Products", cnNwind)
        Dim ds as DataSet
        'Fill the DataSet. 
        ds = New DataSet()
        daProducts.Fill(ds, "Products")
        'Bind the XmlDataDocument to the DataSet
        xmldoc = New Xml.XmlDataDocument(ds)
    
        Me.DataGrid1.DataSource = ds
        Me.DataGrid1.DataMember = "Products"
        'Workaround    
        'Dim dummy As String
        'dummy = xmldoc.InnerText
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
                        
  7. To add the XmlDataDocument class NodeChanged event, paste the following code:

    Private Sub xmldoc_NodeChanged(ByVal sender As Object, ByVal e As System.Xml.XmlNodeChangedEventArgs) Handles xmldoc.NodeChanged
        MsgBox("xmldoc_NodeChanged event fired")
    End Sub
                        
  8. Compile and run the project. Notice that the DataGrid is filled with products data.
  9. Change the data in the grid, and then click Next row. Notice that the XmlDataDocument does not fire the NodeChanged event.
  10. To use the InnerText property of the XmlDataDocument, uncomment the two lines of code after "Workaround", and then run the project.
  11. Change the data in the grid, and then click Next row. Notice the following message:

    xmldoc_NodeChanged event fired
                        


REFERENCES

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

313649 INFO: Roadmap for XML Integration with ADO.NET


Keywords: kbbug kbnofix KB326599