指定した DataRow に関連付けられている XmlElement を取得します。
Public Function GetElementFromRow( _
ByVal r As DataRow _) As XmlElement
[C#]
public XmlElement GetElementFromRow(DataRowr);
[C++]
public: XmlElement* GetElementFromRow(DataRow* r);
[JScript]
public function GetElementFromRow(
r : DataRow) : XmlElement;
パラメータ
- r
取得する対象の、関連付けられた XmlElement を持つ DataRow 。
戻り値
指定した DataRow の表現を格納している XmlElement 。
使用例
[Visual Basic, C#, C++] DataSet を XmlDataDocument に読み込み、最初の顧客レコードを表す XmlElement を作成する例を次に示します。
[Visual Basic, C#, C++] この例では、SQL Server 2000 Northwind データベースを使用しています。
Imports System
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
[C#]
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);
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.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 = new DataSet();
//Create the connection string
String* sConnect;
sConnect=S"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 = S"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,S"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->Item[0]->Rows->Item[0];
XmlElement* elem = doc->GetElementFromRow(row);
Console::WriteLine(elem->OuterXml);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
XmlDataDocument クラス | XmlDataDocument メンバ | System.Xml 名前空間 | DataSet | DataTable