DataSet Property
Collapse the table of content
Expand the table of content

XmlDataDocument.DataSet Property

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

[Visual Basic]
Public ReadOnly Property DataSet As DataSet
[C#]
public DataSet DataSet {get;}
[C++]
public: __property DataSet* get_DataSet();
[JScript]
public function get DataSet() : DataSet;

Property Value

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

Remarks

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.

Example

[Visual Basic, C#, C++] The following example modifies the price of a book using the DataSet methods.

[Visual Basic] 
imports System
imports System.Data
imports System.Xml

public class Sample

  public shared sub Main()

    'Create an XmlDataDocument.
    Dim doc as XmlDataDocument = new XmlDataDocument()

    'Load the schema.
    doc.DataSet.ReadXmlSchema("store.xsd") 
 
    'Load the XML data.
    doc.Load("2books.xml")

    'Change the price on the first book using the DataSet methods.
    Dim books as DataTable = doc.DataSet.Tables.Item("book")
    books.Rows.Item(0).Item("price") = "12.95" 

    Console.WriteLine("Display the modified XML data...")
    doc.Save(Console.Out)

  end sub
end class

[C#] 
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.
     doc.DataSet.ReadXmlSchema("store.xsd"); 

     //Load the XML data.
     doc.Load("2books.xml");

     //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...");
     doc.Save(Console.Out);
  }
} // End class

[C++] 
#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.
     doc->DataSet->ReadXmlSchema(S"store.xsd"); 

     //Load the XML data.
     doc->Load(S"2books.xml");

     //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...");
     doc->Save(Console::Out);
}

[Visual Basic, C#, C++] The example uses the following two files as input.

[Visual Basic, C#, C++] 2books.xml

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

[Visual Basic, C#, C++] store.xsd

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

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

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

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

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

</xsd:schema>

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

XmlDataDocument Class | XmlDataDocument Members | System.Xml Namespace | DataSet | DataTable

Show:
© 2016 Microsoft