XmlDataDocument Constructor (DataSet)

 

Initializes a new instance of the XmlDataDocument class with the specified DataSet.

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

public XmlDataDocument(
	DataSet dataset
)

Parameters

dataset
Type: System.Data.DataSet

The DataSet to load into XmlDataDocument.

The XmlDataDocument is synchronized with the specified DataSet. Any data in the DataSet is immediately available through the XmlDataDocument. Any changes in the DataSet are propagated in the XmlDataDocument. Any changes made in the XmlDataDocument, provided they match the DataSet schema, are propagated in the DataSet.

The following example loads a customer table into an XmlDataDocument.

The example uses the SQL Server 2000 Northwind database.

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

public class Sample
{
  public static void Main()
  {
     DataSet dsNorthwind = new DataSet();

     //Create the connection string.           
     String sConnect;
     sConnect="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind";     

     //Create a connection object to connect to the northwind db.
     SqlConnection nwconnect = new SqlConnection(sConnect);

     //Create a command string to select all the customers in the WA region.
     String sCommand = "Select * from Customers where Region='WA'";

     //Create an adapter to load the DataSet.
     SqlDataAdapter myDataAdapter = new SqlDataAdapter(sCommand, nwconnect);

     //Fill the DataSet with the selected records.
     myDataAdapter.Fill(dsNorthwind,"Customers");

     //Load the document with the DataSet.
     XmlDataDocument doc = new XmlDataDocument(dsNorthwind);   

     //Display the XmlDataDocument.
     doc.Save(Console.Out);

  }
}

.NET Framework
Available since 1.1
Return to top
Show: