DataTable.ReadXmlSchema メソッド (String)
アセンブリ: System.Data (system.data.dll 内)


ReadXmlSchema メソッドを使用して、DataTable のスキーマを作成します。スキーマにはテーブル、リレーションシップ、制約の各定義が含まれています。
XML ドキュメントにスキーマを書き込むには、WriteXmlSchema メソッドを使用します。
通常、ReadXmlSchema メソッドは、DataTable への格納に使用する ReadXml メソッドの呼び出しの前に呼び出されます。

次に示すコンソール アプリケーションの例では、新しい DataTable を作成し、このテーブルのスキーマをファイルに書き込みます。次に、このファイルをソースとして使用して、新しい DataTable を作成し、そのスキーマを保存済み XML スキーマから読み取ります。
Private Sub DemonstrateReadWriteXMLSchemaWithFile() Dim table As DataTable = CreateTestTable("XmlDemo") PrintSchema(table, "Original table") Dim xmlFile As String = "SchemaDemo.xml" ' Write the schema to XML. table.WriteXmlSchema(xmlFile) Dim newTable As New DataTable newTable.ReadXmlSchema(xmlFile) ' Print out values in the table. PrintSchema(newTable, "New Table") End Sub Private Function CreateTestTable(ByVal tableName As String) _ As DataTable ' Create a test DataTable with two columns and a few rows. Dim table As New DataTable(tableName) Dim column As New DataColumn("id", GetType(System.Int32)) column.AutoIncrement = True table.Columns.Add(column) column = New DataColumn("item", GetType(System.String)) table.Columns.Add(column) ' Add ten rows. Dim row As DataRow For i As Integer = 0 To 9 row = table.NewRow() row("item") = "item " & i table.Rows.Add(row) Next i table.AcceptChanges() Return table End Function Private Sub PrintSchema(ByVal table As DataTable, _ ByVal label As String) ' Display the schema of the supplied DataTable: Console.WriteLine(label) For Each column As DataColumn In table.Columns Console.WriteLine("{0}{1}: {2}", ControlChars.Tab, _ column.ColumnName, column.DataType.Name) Next column End Sub
private static void DemonstrateReadWriteXMLSchemaWithFile() { DataTable table = CreateTestTable("XmlDemo"); PrintSchema(table, "Original table"); // Write the schema to XML in a file. string xmlFile = "C:\\SchemaDemo.xml"; table.WriteXmlSchema(xmlFile); DataTable newTable = new DataTable(); newTable.ReadXmlSchema(xmlFile); // Print out values in the table. PrintSchema(newTable, "New table"); } private static DataTable CreateTestTable(string tableName) { // Create a test DataTable with two columns and a few rows. DataTable table = new DataTable(tableName); DataColumn column = new DataColumn("id", typeof(System.Int32)); column.AutoIncrement = true; table.Columns.Add(column); column = new DataColumn("item", typeof(System.String)); table.Columns.Add(column); // Add ten rows. DataRow row; for (int i = 0; i <= 9; i++) { row = table.NewRow(); row["item"] = "item " + i; table.Rows.Add(row); } table.AcceptChanges(); return table; } private static void PrintSchema(DataTable table, string label) { // Display the schema of the supplied DataTable: Console.WriteLine(label); foreach (DataColumn column in table.Columns) { Console.WriteLine("\t{0}: {1}", column.ColumnName, column.DataType.Name); } Console.WriteLine(); }

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


DataTable.ReadXmlSchema メソッド (TextReader)
アセンブリ: System.Data (system.data.dll 内)


ReadXmlSchema メソッドを使用して、DataTable のスキーマを作成します。スキーマにはテーブル、リレーションシップ、制約の各定義が含まれています。
XML ドキュメントにスキーマを書き込むには、WriteXmlSchema メソッドを使用します。
通常、ReadXmlSchema メソッドは、DataTable への格納に使用する ReadXml メソッドの呼び出しの前に呼び出されます。

次に示すコンソール アプリケーションの例では、新しい DataTable を作成し、このテーブルのスキーマを MemoryStream に書き込みます。次に、StreamReader (TextReader から継承されます) をソースとして使用して、新しい DataTable を作成し、そのスキーマを保存済み XML スキーマから読み取ります。
Private Sub DemonstrateReadWriteXMLSchemaWithReader() Dim table As DataTable = CreateTestTable("XmlDemo") PrintSchema(table, "Original table") ' Write the schema to XML in a memory stream. Dim xmlStream As New System.IO.MemoryStream() table.WriteXmlSchema(xmlStream) ' Rewind the memory stream. xmlStream.Position = 0 Dim newTable As New DataTable Dim reader As New System.IO.StreamReader(xmlStream) newTable.ReadXmlSchema(reader) ' Print out values in the table. PrintSchema(newTable, "New Table") End Sub Private Function CreateTestTable(ByVal tableName As String) _ As DataTable ' Create a test DataTable with two columns and a few rows. Dim table As New DataTable(tableName) Dim column As New DataColumn("id", GetType(System.Int32)) column.AutoIncrement = True table.Columns.Add(column) column = New DataColumn("item", GetType(System.String)) table.Columns.Add(column) ' Add ten rows. Dim row As DataRow For i As Integer = 0 To 9 row = table.NewRow() row("item") = "item " & i table.Rows.Add(row) Next i table.AcceptChanges() Return table End Function Private Sub PrintSchema(ByVal table As DataTable, _ ByVal label As String) ' Display the schema of the supplied DataTable: Console.WriteLine(label) For Each column As DataColumn In table.Columns Console.WriteLine("{0}{1}: {2}", ControlChars.Tab, _ column.ColumnName, column.DataType.Name) Next column End Sub
private static void DemonstrateReadWriteXMLSchemaWithReader() { DataTable table = CreateTestTable("XmlDemo"); PrintSchema(table, "Original table"); // Write the schema to XML in a memory stream. System.IO.MemoryStream xmlStream = new System.IO.MemoryStream(); table.WriteXmlSchema(xmlStream); // Rewind the memory stream. xmlStream.Position = 0; DataTable newTable = new DataTable(); System.IO.StreamReader reader = new System.IO.StreamReader(xmlStream); newTable.ReadXmlSchema(reader); // Print out values in the table. PrintSchema(newTable, "New table"); } private static DataTable CreateTestTable(string tableName) { // Create a test DataTable with two columns and a few rows. DataTable table = new DataTable(tableName); DataColumn column = new DataColumn("id", typeof(System.Int32)); column.AutoIncrement = true; table.Columns.Add(column); column = new DataColumn("item", typeof(System.String)); table.Columns.Add(column); // Add ten rows. DataRow row; for (int i = 0; i <= 9; i++) { row = table.NewRow(); row["item"] = "item " + i; table.Rows.Add(row); } table.AcceptChanges(); return table; } private static void PrintSchema(DataTable table, string label) { // Display the schema of the supplied DataTable: Console.WriteLine(label); foreach (DataColumn column in table.Columns) { Console.WriteLine("\t{0}: {1}", column.ColumnName, column.DataType.Name); } Console.WriteLine(); }

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


DataTable.ReadXmlSchema メソッド (Stream)
アセンブリ: System.Data (system.data.dll 内)


ReadXmlSchema メソッドを使用して、DataTable のスキーマを作成します。スキーマにはテーブル、リレーションシップ、制約の各定義が含まれています。
XML ドキュメントにスキーマを書き込むには、WriteXmlSchema メソッドを使用します。
通常、ReadXmlSchema メソッドは、DataTable への格納に使用する ReadXml メソッドの呼び出しの前に呼び出されます。

次に示すコンソール アプリケーションの例では、新しい DataTable を作成し、このテーブルのスキーマを MemoryStream に書き込みます。次に、新しい DataTable を作成し、そのスキーマを保存済み XML スキーマから読み取ります。
Private Sub DemonstrateReadWriteXMLSchemaWithStream() Dim table As DataTable = CreateTestTable("XmlDemo") PrintSchema(table, "Original table") ' Write the schema to XML in a memory stream. Dim xmlStream As New System.IO.MemoryStream() table.WriteXmlSchema(xmlStream) ' Rewind the memory stream. xmlStream.Position = 0 Dim newTable As New DataTable newTable.ReadXmlSchema(xmlStream) ' Print out values in the table. PrintSchema(newTable, "New Table") End Sub Private Function CreateTestTable(ByVal tableName As String) _ As DataTable ' Create a test DataTable with two columns and a few rows. Dim table As New DataTable(tableName) Dim column As New DataColumn("id", GetType(System.Int32)) column.AutoIncrement = True table.Columns.Add(column) column = New DataColumn("item", GetType(System.String)) table.Columns.Add(column) ' Add ten rows. Dim row As DataRow For i As Integer = 0 To 9 row = table.NewRow() row("item") = "item " & i table.Rows.Add(row) Next i table.AcceptChanges() Return table End Function Private Sub PrintSchema(ByVal table As DataTable, _ ByVal label As String) ' Display the schema of the supplied DataTable: Console.WriteLine(label) For Each column As DataColumn In table.Columns Console.WriteLine("{0}{1}: {2}", ControlChars.Tab, _ column.ColumnName, column.DataType.Name) Next column End Sub
private static void DemonstrateReadWriteXMLSchemaWithStream() { DataTable table = CreateTestTable("XmlDemo"); PrintSchema(table, "Original table"); // Write the schema to XML in a memory stream. System.IO.MemoryStream xmlStream = new System.IO.MemoryStream(); table.WriteXmlSchema(xmlStream); // Rewind the memory stream. xmlStream.Position = 0; DataTable newTable = new DataTable(); newTable.ReadXmlSchema(xmlStream); // Print out values in the table. PrintSchema(newTable, "New table"); } private static DataTable CreateTestTable(string tableName) { // Create a test DataTable with two columns and a few rows. DataTable table = new DataTable(tableName); DataColumn column = new DataColumn("id", typeof(System.Int32)); column.AutoIncrement = true; table.Columns.Add(column); column = new DataColumn("item", typeof(System.String)); table.Columns.Add(column); // Add ten rows. DataRow row; for (int i = 0; i <= 9; i++) { row = table.NewRow(); row["item"] = "item " + i; table.Rows.Add(row); } table.AcceptChanges(); return table; } private static void PrintSchema(DataTable table, string label) { // Display the schema of the supplied DataTable: Console.WriteLine(label); foreach (DataColumn column in table.Columns) { Console.WriteLine("\t{0}: {1}", column.ColumnName, column.DataType.Name); } Console.WriteLine(); }

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


DataTable.ReadXmlSchema メソッド (XmlReader)
アセンブリ: System.Data (system.data.dll 内)


ReadXmlSchema メソッドを使用して、DataTable のスキーマを作成します。スキーマにはテーブル、リレーションシップ、制約の各定義が含まれています。
XML ドキュメントにスキーマを書き込むには、WriteXmlSchema メソッドを使用します。
通常、ReadXmlSchema メソッドは、DataTable への格納に使用する ReadXml メソッドの呼び出しの前に呼び出されます。

次に示すコンソール アプリケーションの例では、新しい DataTable を作成し、このテーブルのスキーマを MemoryStream に書き込みます。次に、XmlTextReader (XmlReader から継承されます) をソースとして使用して、新しい DataTable を作成し、そのスキーマを保存済み XML スキーマから読み取ります。
Private Sub DemonstrateReadWriteXMLSchemaWithReader() Dim table As DataTable = CreateTestTable("XmlDemo") PrintSchema(table, "Original table") ' Write the schema to XML in a memory stream. Dim xmlStream As New System.IO.MemoryStream() table.WriteXmlSchema(xmlStream) ' Rewind the memory stream. xmlStream.Position = 0 Dim newTable As New DataTable Dim reader As New System.Xml.XmlTextReader(xmlStream) newTable.ReadXmlSchema(reader) ' Print out values in the table. PrintSchema(newTable, "New Table") End Sub Private Function CreateTestTable(ByVal tableName As String) _ As DataTable ' Create a test DataTable with two columns and a few rows. Dim table As New DataTable(tableName) Dim column As New DataColumn("id", GetType(System.Int32)) column.AutoIncrement = True table.Columns.Add(column) column = New DataColumn("item", GetType(System.String)) table.Columns.Add(column) ' Add ten rows. Dim row As DataRow For i As Integer = 0 To 9 row = table.NewRow() row("item") = "item " & i table.Rows.Add(row) Next i table.AcceptChanges() Return table End Function Private Sub PrintSchema(ByVal table As DataTable, _ ByVal label As String) ' Display the schema of the supplied DataTable: Console.WriteLine(label) For Each column As DataColumn In table.Columns Console.WriteLine("{0}{1}: {2}", ControlChars.Tab, _ column.ColumnName, column.DataType.Name) Next column End Sub
private static void DemonstrateReadWriteXMLSchemaWithReader() { DataTable table = CreateTestTable("XmlDemo"); PrintSchema(table, "Original table"); // Write the schema to XML in a memory stream. System.IO.MemoryStream xmlStream = new System.IO.MemoryStream(); table.WriteXmlSchema(xmlStream); // Rewind the memory stream. xmlStream.Position = 0; DataTable newTable = new DataTable(); System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(xmlStream); newTable.ReadXmlSchema(reader); // Print out values in the table. PrintSchema(newTable, "New table"); } private static DataTable CreateTestTable(string tableName) { // Create a test DataTable with two columns and a few rows. DataTable table = new DataTable(tableName); DataColumn column = new DataColumn("id", typeof(System.Int32)); column.AutoIncrement = true; table.Columns.Add(column); column = new DataColumn("item", typeof(System.String)); table.Columns.Add(column); // Add ten rows. DataRow row; for (int i = 0; i <= 9; i++) { row = table.NewRow(); row["item"] = "item " + i; table.Rows.Add(row); } table.AcceptChanges(); return table; } private static void PrintSchema(DataTable table, string label) { // Display the schema of the supplied DataTable: Console.WriteLine(label); foreach (DataColumn column in table.Columns) { Console.WriteLine("\t{0}: {1}", column.ColumnName, column.DataType.Name); } Console.WriteLine(); }

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


DataTable.ReadXmlSchema メソッド

名前 | 説明 |
---|---|
DataTable.ReadXmlSchema (Stream) | 指定したストリームを使用して、XML スキーマを DataTable に読み込みます。 .NET Compact Framework によってサポートされています。 |
DataTable.ReadXmlSchema (String) | 指定したファイルから DataTable に XML スキーマを読み込みます。 .NET Compact Framework によってサポートされています。 |
DataTable.ReadXmlSchema (TextReader) | 指定した TextReader を使用して、XML スキーマを DataTable に読み込みます。 .NET Compact Framework によってサポートされています。 |
DataTable.ReadXmlSchema (XmlReader) | 指定した XmlReader を使用して、XML スキーマを DataTable に読み込みます。 .NET Compact Framework によってサポートされています。 |
