XmlDataDocument コンストラクタ (DataSet)
アセンブリ: System.Data (system.data.dll 内)


XmlDataDocument は、指定した DataSet と同期されます。DataSet のデータは、XmlDataDocument を通じてすぐに使用できます。DataSet での変更は、XmlDataDocument に反映されます。XmlDataDocument での変更は、その変更が DataSet スキーマに一致していれば、DataSet に反映されます。

顧客テーブルを XmlDataDocument に読み込む例を次に示します。
この例では、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) 'Display the XmlDataDocument. doc.Save(Console.Out) end sub end class
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); } }
#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 ); //Display the XmlDataDocument. doc->Save( Console::Out ); }
import System.*; import System.Data.*; import System.Xml.*; import System.Data.SqlClient.*; public class Sample { public static void main(String[] args) { 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.get_Out()); } //main } //Sample

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlDataDocument コンストラクタ

名前 | 説明 |
---|---|
XmlDataDocument () | XmlDataDocument クラスの新しいインスタンスを初期化します。 |
XmlDataDocument (DataSet) | DataSet を指定して、XmlDataDocument クラスの新しいインスタンスを初期化します。 |

XmlDataDocument コンストラクタ ()
アセンブリ: System.Data (system.data.dll 内)



Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- XmlDataDocument コンストラクタのページへのリンク