Đang chuẩn bị liên kết để tải về tài liệu:
Synchronizing a DataSet with an XML Document

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

[ Team LiB ] Recipe 8.3 Synchronizing a DataSet with an XML Document Problem You need to work with both a DataSet and its XML representation. Solution Use a synchronized DataSet and XmlDataDocument. The sample code contains two event handlers and one method: | Team LiB Recipe 8.3 Synchronizing a DataSet with an XML Document Problem You need to work with both a DataSet and its XML representation. Solution Use a synchronized DataSet and XmlDataDocument. The sample code contains two event handlers and one method Go Button.Click Synchronizes a DataSet and an XmlDataDocument using one of three methods specified by the user. The default view for the Orders table of the DataSet is bound to the data grid on the form and the contents of the XmlDataDocument are displayed in the text box. Clear Button.Click Clears the contents of the data grid displaying the DataSet and the text box displaying the contents of the XmlDataDocument. FillDataSet This method loads the DataSet with a subset of the Orders and Order Details data from Northwind and creates a relation between the tables. The C code is shown in Example 8-5. Example 8-5. File SyncDataSetWithXmlDocForm.cs Namespaces variables and constants using System using System.Configuration using System.Windows.Forms using System.Xml using System.Data using System.Data.SqlClient Table name constants private const String ORDERS_TABLE Orders private const String ORDERDETAILS_TABLE OrderDetails Relation name constants private const String ORDERS_ORDERDETAILS_RELATION Orders_OrderDetails_Relation Field name constants private const String ORDERID_FIELD OrderlD private const String XMLFILENAME ConfigurationSettings.AppSettings Project_Directory @ Chapter 08 Orders_OrderDetails.xml . . . private void goButton_Click object sender System.EventArgs e Cursor.Current Cursors.WaitCursor DataSet ds null XmlDataDocument xmlDoc null if methodlRadioButton.Checked Load DataSet with schema and data. ds FillDataSet true Get the XML document for the DataSet. xmlDoc new XmlDataDocument ds else if method2RadioButton.Checked Create DataSet with schema but no data. ds FillDataSet false Get the XML document for the DataSet. xmlDoc new XmlDataDocument ds Load the data into the XML document from the XML file. .