XmlDataDocument.GetElementFromRow(DataRow) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索与指定 XmlElement 关联的 DataRow。
public:
System::Xml::XmlElement ^ GetElementFromRow(System::Data::DataRow ^ r);
public System.Xml.XmlElement GetElementFromRow (System.Data.DataRow r);
member this.GetElementFromRow : System.Data.DataRow -> System.Xml.XmlElement
Public Function GetElementFromRow (r As DataRow) As XmlElement
参数
- r
- DataRow
想要检索其关联 DataRow
的 XmlElement
。
返回
包含指定 XmlElement
的表示形式的 DataRow
。
示例
以下示例将 加载 DataSet
到 中, XmlDataDocument
然后创建表示第一个 XmlElement
客户记录的 。
该示例使用 SQL Server 2000 Northwind 数据库。
#using <System.Xml.dll>
#using <System.Transactions.dll>
#using <System.EnterpriseServices.dll>
#using <System.dll>
#using <System.Data.dll>
using namespace System;
using namespace System::Data;
using namespace System::Xml;
using namespace System::Data::SqlClient;
int main()
{
DataSet^ dsNorthwind = gcnew 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 = gcnew 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 = gcnew SqlDataAdapter( sCommand,nwconnect );
//Fill the DataSet with the selected records.
myDataAdapter->Fill( dsNorthwind, "Customers" );
//Load the document with the DataSet.
XmlDataDocument^ doc = gcnew 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 );
}
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);
}
}
Imports System.Xml
Imports System.Data
Imports System.Data.SqlClient
public class Sample
public shared sub Main()
Dim dsNorthwind as DataSet = new DataSet()
'Create the connection string.
Dim sConnect as String
sConnect="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind"
'Create a connection object to connect to the northwind db.
Dim nwconnect as SqlConnection
nwconnect = new SqlConnection(sConnect)
'Create a command string to select all the customers in the WA region.
Dim sCommand as String = "Select * from Customers where Region='WA'"
'Create an Adapter to load the DataSet.
Dim myDataAdapter as SqlDataAdapter
myDataAdapter = new SqlDataAdapter(sCommand, nwconnect)
'Fill the DataSet with the selected records.
myDataAdapter.Fill(dsNorthwind, "Customers")
'Load the document with the DataSet.
Dim doc as XmlDataDocument = new XmlDataDocument(dsNorthwind)
'Create an element representing the first customer record.
Dim row as DataRow = doc.DataSet.Tables.Item(0).Rows.Item(0)
Dim elem as XmlElement = doc.GetElementFromRow(row)
Console.WriteLine(elem.OuterXml)
end sub
end class