|
이 문서는 기계로 번역한 것입니다. 원본 텍스트를 보려면 포인터를 문서의 문장 위로 올리십시오. 추가 정보
|
번역
원본
|
DataTable.WriteXmlSchema 메서드
.NET Framework 4.5
이 멤버는 오버로드됩니다. 구문, 사용법 및 예제를 비롯하여 이 멤버에 대한 자세한 내용을 보려면 오버로드 목록에서 이름을 클릭합니다.
| 이름 | 설명 | |
|---|---|---|
|
WriteXmlSchema(Stream) |
|
|
WriteXmlSchema(String) |
|
|
WriteXmlSchema(TextWriter) |
|
|
WriteXmlSchema(XmlWriter) |
|
|
WriteXmlSchema(Stream, Boolean) |
|
|
WriteXmlSchema(String, Boolean) |
|
|
WriteXmlSchema(TextWriter, Boolean) |
|
|
WriteXmlSchema(XmlWriter, Boolean) |
|
참고
|
|---|
|
|
static void Main() { DataSet ds = new DataSet(); DataTable customerTable = GetCustomers(); DataTable orderTable = GetOrders(); ds.Tables.Add(customerTable); ds.Tables.Add(orderTable); ds.Relations.Add("CustomerOrder", new DataColumn[] { customerTable.Columns[0] }, new DataColumn[] { orderTable.Columns[1] }, true); System.IO.StringWriter writer = new System.IO.StringWriter(); customerTable.WriteXmlSchema(writer, false); PrintOutput(writer, "Customer table, without hierarchy"); writer = new System.IO.StringWriter(); customerTable.WriteXmlSchema(writer, true); PrintOutput(writer, "Customer table, with hierarchy"); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } private static DataTable GetCustomers() { // Create sample Customers table, in order // to demonstrate the behavior of the DataTableReader. DataTable table = new DataTable(); // Create two columns, ID and Name. DataColumn idColumn = table.Columns.Add("ID", typeof(System.Int32)); table.Columns.Add("Name", typeof(System.String)); // Set the ID column as the primary key column. table.PrimaryKey = new DataColumn[] { idColumn }; table.Rows.Add(new object[] { 1, "Mary" }); table.Rows.Add(new object[] { 2, "Andy" }); table.Rows.Add(new object[] { 3, "Peter" }); table.Rows.Add(new object[] { 4, "Russ" }); table.AcceptChanges(); return table; } private static DataTable GetOrders() { // Create sample Customers table, in order // to demonstrate the behavior of the DataTableReader. DataTable table = new DataTable(); // Create three columns; OrderID, CustomerID, and OrderDate. table.Columns.Add(new DataColumn("OrderID", typeof(System.Int32))); table.Columns.Add(new DataColumn("CustomerID", typeof(System.Int32))); table.Columns.Add(new DataColumn("OrderDate", typeof(System.DateTime))); // Set the OrderID column as the primary key column. table.PrimaryKey = new DataColumn[] { table.Columns[0] }; table.Rows.Add(new object[] { 1, 1, "12/2/2003" }); table.Rows.Add(new object[] { 2, 1, "1/3/2004" }); table.Rows.Add(new object[] { 3, 2, "11/13/2004" }); table.Rows.Add(new object[] { 4, 3, "5/16/2004" }); table.Rows.Add(new object[] { 5, 3, "5/22/2004" }); table.Rows.Add(new object[] { 6, 4, "6/15/2004" }); table.AcceptChanges(); return table; } private static void PrintOutput(System.IO.TextWriter writer, string caption) { Console.WriteLine("=============================="); Console.WriteLine(caption); Console.WriteLine("=============================="); Console.WriteLine(writer.ToString()); }
==============================
Customer table, without hierarchy
==============================
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Ta
ble1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table1" />
<xs:field xpath="ID" />
</xs:unique>
</xs:element>
</xs:schema>
==============================
Customer table, with hierarchy
==============================
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table2">
<xs:complexType>
<xs:sequence>
<xs:element name="OrderID" type="xs:int" />
<xs:element name="CustomerID" type="xs:int" minOccurs="0" />
<xs:element name="OrderDate" type="xs:dateTime" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table1" />
<xs:field xpath="ID" />
</xs:unique>
<xs:unique name="Table2_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table2" />
<xs:field xpath="OrderID" />
</xs:unique>
<xs:keyref name="CustomerOrder" refer="Constraint1">
<xs:selector xpath=".//Table2" />
<xs:field xpath="CustomerID" />
</xs:keyref>
</xs:element>
</xs:schema>