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
- Start Microsoft Visual Studio .NET. On the File menu, click New and then click Projects.
- Click Visual Basic Projects under Project Types, and then click Windows Application under Templates. By default, Form1.vb is created.
- Drag a DataGrid control (DataGrid1) and a Button control (Button1) from the toolbox to Form1.
Import the following namespaces:
Imports System.Xml Imports System.Data.SqlClient
Dim the following as a global variable:
Dim WithEvents xmldoc As Xml.XmlDataDocument
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
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
- Compile and run the project. Notice that the DataGrid is filled with products data.
- Change the data in the grid, and then click Next row. Notice that the XmlDataDocument does not fire the NodeChanged event.
- To use the InnerText property of the XmlDataDocument, uncomment the two lines of code after "Workaround", and then run the project.
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