This documentation is archived and is not being maintained.

XmlDataDocument.DataSet Property

Gets a DataSet that provides a relational representation of the data in the XmlDataDocument.

Namespace:  System.Xml
Assembly:  System.Data (in System.Data.dll)

public DataSet DataSet { get; }

Property Value

Type: System.Data.DataSet
A DataSet that can be used to access the data in the XmlDataDocument using a relational model.

The DataSet enables you to access the data in the XmlDataDocument using a relational model. This means that you can handle the data as tables and views, rows and columns, relations, and so on. Changes made in the DataSet are immediately visible in the XmlDataDocument.

The following example modifies the price of a book using the DataSet methods.

using System;
using System.Data;
using System.Xml;

public class Sample
  public static void Main()
     //Create an XmlDataDocument.
     XmlDataDocument doc = new XmlDataDocument();

     //Load the schema file.

     //Load the XML data.

     //Update the price on the first book using the DataSet methods.
     DataTable books = doc.DataSet.Tables["book"];
     books.Rows[0]["price"] = "12.95";  

     Console.WriteLine("Display the modified XML data...");
} // End class
#using <mscorlib.dll>
#using <System.dll>
#using <System.Xml.dll>
#using <System.Data.dll>
using namespace System;
using namespace System::Data;
using namespace System::Xml;

int main()
     //Create an XmlDataDocument.
     XmlDataDocument* doc = new XmlDataDocument();

     //Load the schema file.

     //Load the XML data.

     //Update the price on the first book using the DataSet methods.
     DataTable* books = doc->DataSet->Tables->Item[S"book"];
     books->Rows->Item[0]->Item[S"price"] = S"12.95";  

     Console::WriteLine(S"Display the modified XML data...");

The example uses the following two files as input.


<!--sample XML fragment-->
  <book genre='novel' ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
  <book genre='novel' ISBN='1-861001-57-5'>
    <title>Pride And Prejudice</title>


<xsd:schema xmlns:xsd="">

 <xsd:element name="bookstore" type="bookstoreType"/>

 <xsd:complexType name="bookstoreType">
  <xsd:sequence maxOccurs="unbounded">
   <xsd:element name="book"  type="bookType"/>

 <xsd:complexType name="bookType">
   <xsd:element name="title" type="xsd:string"/>
   <xsd:element name="author" type="authorName"/>
   <xsd:element name="price"  type="xsd:decimal"/>
  <xsd:attribute name="genre" type="xsd:string"/>

 <xsd:complexType name="authorName">
   <xsd:element name="first-name"  type="xsd:string"/>
   <xsd:element name="last-name" type="xsd:string"/>


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0