Export (0) Print
Expand All

XmlDataDocument.GetElementFromRow Method

Retrieves the XmlElement associated with the specified DataRow.

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

public XmlElement GetElementFromRow(
	DataRow r
)

Parameters

r
Type: System.Data.DataRow

The DataRow whose associated XmlElement you want to retrieve.

Return Value

Type: System.Xml.XmlElement
The XmlElement containing a representation of the specified DataRow.

The following example loads a DataSet into an XmlDataDocument and then creates an XmlElement representing the first customer record.

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);   

     //Create an element representing the first customer record.
     DataRow row = doc.DataSet.Tables[0].Rows[0];
     XmlElement elem = doc.GetElementFromRow(row);
     Console.WriteLine(elem.OuterXml);    
  }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft