DataSet.ReadXmlSchema 方法

定義

將 XML 結構描述讀入 DataSet

多載

ReadXmlSchema(Stream)

從指定的 Stream,將 XML 結構描述讀入 DataSet

ReadXmlSchema(TextReader)

從指定的 TextReader,將 XML 結構描述讀入 DataSet

ReadXmlSchema(String)

從指定的檔案,將 XML 結構描述讀入 DataSet

ReadXmlSchema(XmlReader)

從指定的 XmlReader,將 XML 結構描述讀入 DataSet

ReadXmlSchema(Stream)

來源:
DataSet.cs
來源:
DataSet.cs
來源:
DataSet.cs

從指定的 Stream,將 XML 結構描述讀入 DataSet

public void ReadXmlSchema (System.IO.Stream? stream);
public void ReadXmlSchema (System.IO.Stream stream);

參數

stream
Stream

要讀取的來源 Stream

範例

下列範例會 FileStream 建立 物件來讀取 XML 架構,並使用 物件叫 ReadXmlSchema 用 方法。

private void ReadSchemaFromFileStream(DataSet thisDataSet)
{
    // Set the file path and name.
    // Modify this for your purposes.
    string filename="Schema.xml";

    // Create the FileStream object with the file name,
    // and set to open the file.
    System.IO.FileStream stream =
        new System.IO.FileStream(filename,System.IO.FileMode.Open);

    // Read the schema into the DataSet.
    thisDataSet.ReadXmlSchema(stream);

    // Close the FileStream.
    stream.Close();
}

備註

ReadXmlSchema使用方法來建立的DataSet架構。 架構包含數據表、關聯性和條件約束定義。 若要將架構寫入 XML 檔,請使用 WriteXmlSchema 方法。

XML 架構是使用 XSD 標準來撰寫。

注意

如果 msdata:DataType 和 xs:type 類型不相符,可能會發生數據損毀。 不會擲回例外狀況。

ReadXmlSchemaReadXml 用 用來填滿 DataSet的方法之前,通常會叫用 方法。

衍生自類別的 Stream 類別包括 BufferedStreamFileStreamMemoryStreamNetworkStream

注意

如果您的架構 DataSet 包含相同名稱但類型不同的元素,在相同的命名空間中,當您嘗試使用 將架構讀取至 DataSetReadXmlSchema時,就會擲回例外狀況。 如果您使用 .NET Framework 1.0 版,則不會發生此例外狀況。

另請參閱

適用於

.NET 9 及其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ReadXmlSchema(TextReader)

來源:
DataSet.cs
來源:
DataSet.cs
來源:
DataSet.cs

從指定的 TextReader,將 XML 結構描述讀入 DataSet

public void ReadXmlSchema (System.IO.TextReader? reader);
public void ReadXmlSchema (System.IO.TextReader reader);

參數

reader
TextReader

要讀取的來源 TextReader

範例

下列範例會 StreamReader 建立 物件來讀取架構,並使用 物件叫 ReadXmlSchema 用 方法。

private void ReadSchemaFromStreamReader()
{
    // Create the DataSet to read the schema into.
    DataSet thisDataSet = new DataSet();

    // Set the file path and name. Modify this for your purposes.
    string filename="Schema.xml";

    // Create a StreamReader object with the file path and name.
    System.IO.StreamReader readStream =
        new System.IO.StreamReader(filename);

    // Invoke the ReadXmlSchema method with the StreamReader object.
    thisDataSet.ReadXmlSchema(readStream);

    // Close the StreamReader
    readStream.Close();
}

備註

ReadXmlSchema使用方法來建立的DataSet架構。 架構包含數據表、關聯性和條件約束定義。 若要將架構寫入 XML 檔,請使用 WriteXmlSchema 方法。

XML 架構是使用 XSD 標準來撰寫。

注意

如果 msdata:DataType 和 xs:type 類型不相符,可能會發生數據損毀。 不會擲回例外狀況。

ReadXmlSchemaReadXml 用 用來填滿 DataSet的方法之前,通常會叫用 方法。

繼承自類別的 TextReader 類別包括 StreamReaderStringReader 類別。

注意

如果您的架構 DataSet 包含相同名稱但類型不同的元素,在相同的命名空間中,當您嘗試使用 將架構讀取至 DataSetReadXmlSchema時,就會擲回例外狀況。 如果您使用 .NET Framework 1.0 版,則不會發生此例外狀況。

另請參閱

適用於

.NET 9 及其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ReadXmlSchema(String)

來源:
DataSet.cs
來源:
DataSet.cs
來源:
DataSet.cs

從指定的檔案,將 XML 結構描述讀入 DataSet

public void ReadXmlSchema (string fileName);

參數

fileName
String

要讀取的來源檔案名稱 (包括路徑)。

例外狀況

FileIOPermission 並不是設定為 Read

範例

private void ReadSchemaFromFile(){
   // Create the DataSet to read the schema into.
   DataSet thisDataSet = new DataSet();

   // Set the file path and name. Modify this for your purposes.
   string filename="Schema.xml";

   // Invoke the ReadXmlSchema method with the file name.
   thisDataSet.ReadXmlSchema(filename);
}

備註

ReadXmlSchema使用方法來建立的DataSet架構。 架構包含數據表、關聯性和條件約束定義。 若要將架構寫入 XML 檔,請使用 WriteXmlSchema 方法。

XML 架構是使用 XSD 標準來撰寫。

注意

如果 msdata:DataType 和 xs:type 類型不相符,可能會發生數據損毀。 不會擲回例外狀況。

ReadXmlSchemaReadXml 用 用來填滿 DataSet的方法之前,通常會叫用 方法。

注意

如果您的架構 DataSet 包含相同名稱的專案,但類型不同,在相同的命名空間中,當您嘗試使用 將架構讀取至 DataSetReadXmlSchema時,就會擲回例外狀況。 如果您使用 .NET Framework 1.0 版,則不會發生此例外狀況。

另請參閱

適用於

.NET 9 及其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ReadXmlSchema(XmlReader)

來源:
DataSet.cs
來源:
DataSet.cs
來源:
DataSet.cs

從指定的 XmlReader,將 XML 結構描述讀入 DataSet

public void ReadXmlSchema (System.Xml.XmlReader? reader);
public void ReadXmlSchema (System.Xml.XmlReader reader);

參數

reader
XmlReader

要讀取的來源 XmlReader

範例

下列範例會建立新的 DataSetSystem.IO.FileStream 物件。 使用 FileStream 檔案路徑與檔案名稱所建立的物件,可用來建立 System.Xml.XmlTextReader 傳遞為 方法自變數的 ReadXmlSchema

private void ReadSchemaFromXmlTextReader()
{
    // Create the DataSet to read the schema into.
    DataSet thisDataSet = new DataSet();

    // Set the file path and name. Modify this for your purposes.
    string filename="Schema.xml";

    // Create a FileStream object with the file path and name.
    System.IO.FileStream stream = new System.IO.FileStream
        (filename,System.IO.FileMode.Open);

    // Create a new XmlTextReader object with the FileStream.
    System.Xml.XmlTextReader xmlReader=
        new System.Xml.XmlTextReader(stream);

    // Read the schema into the DataSet and close the reader.
    thisDataSet.ReadXmlSchema(xmlReader);
    xmlReader.Close();
}

備註

ReadXmlSchema使用方法來建立的DataSet架構。 架構包含數據表、關聯性和條件約束定義。

XML 架構是使用 XSD 標準來撰寫。

注意

如果 msdata:DataType 和 xs:type 類型不相符,可能會發生數據損毀。 不會擲回例外狀況。

ReadXmlSchemaReadXml 用 用來填滿 DataSet的方法之前,通常會叫用 方法。

類別 System.Xml.XmlReader 是抽象的。 繼承自 XmlReaderSystem.Xml.XmlTextReader 類別是 類別。

注意

如果您的架構 DataSet 包含相同名稱但類型不同的元素,在相同的命名空間中,當您嘗試使用 將架構讀取至 DataSetReadXmlSchema時,就會擲回例外狀況。 如果您使用 .NET Framework 1.0 版,則不會發生此例外狀況。

另請參閱

適用於

.NET 9 及其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1