DataSet.ReadXmlSchema 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将 XML 架构读入 DataSet。
重载
| ReadXmlSchema(Stream) | |
| ReadXmlSchema(TextReader) | 从指定的 TextReader 中将 XML 架构读入 DataSet。 | 
| ReadXmlSchema(String) | 从指定的文件中将 XML 架构读入 DataSet。 | 
| ReadXmlSchema(XmlReader) | 
ReadXmlSchema(Stream)
- Source:
- DataSet.cs
- Source:
- DataSet.cs
- Source:
- DataSet.cs
public:
 void ReadXmlSchema(System::IO::Stream ^ stream);public void ReadXmlSchema (System.IO.Stream? stream);public void ReadXmlSchema (System.IO.Stream stream);member this.ReadXmlSchema : System.IO.Stream -> unitPublic Sub ReadXmlSchema (stream As 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();
}
Private Sub ReadSchemaFromFileStream(thisDataSet As DataSet)
    ' Set the file path and name. Modify this for your purposes.
    Dim filename As String = "Schema.xml"
    ' Create the FileStream object with the file name, 
    ' and set to open the file
    Dim stream As New System.IO.FileStream _
        (filename, System.IO.FileMode.Open)
    ' Read the schema into the DataSet.
    thisDataSet.ReadXmlSchema(stream)
    ' Close the FileStream.
    stream.Close()
End Sub
注解
ReadXmlSchema使用 方法为 DataSet创建架构。 架构包括表、关系和约束定义。 若要将架构写入 XML 文档,请使用 WriteXmlSchema 方法。
XML 架构是使用 XSD 标准编写的。
注意
如果 msdata:DataType 和 xs:type 类型不匹配,则可能发生数据损坏。 不会引发异常。
在 ReadXmlSchema 调用 ReadXml 用于填充 DataSet的方法之前,通常会调用 方法。
派生自 类的 Stream 类包括 BufferedStream、 FileStream、 MemoryStream和 NetworkStream。
注意
如果架构DataSet包含同一名称但类型不同的元素,则在同一命名空间中,则在尝试使用 ReadXmlSchema将架构读取到 时DataSet,将引发异常。 如果使用 .NET Framework版本 1.0,则不会发生此异常。
另请参阅
适用于
ReadXmlSchema(TextReader)
- Source:
- DataSet.cs
- Source:
- DataSet.cs
- Source:
- DataSet.cs
从指定的 TextReader 中将 XML 架构读入 DataSet。
public:
 void ReadXmlSchema(System::IO::TextReader ^ reader);public void ReadXmlSchema (System.IO.TextReader? reader);public void ReadXmlSchema (System.IO.TextReader reader);member this.ReadXmlSchema : System.IO.TextReader -> unitPublic Sub ReadXmlSchema (reader As TextReader)参数
- 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();
}
Private Sub ReadSchemaFromStreamReader()
    ' Create the DataSet to read the schema into.
    Dim thisDataSet As New DataSet()
    ' Set the file path and name. Modify this for your purposes.
    Dim filename As String = "Schema.xml"
    ' Create a StreamReader object with the file path and name.
    Dim readStream As New System.IO.StreamReader(filename)
    ' Invoke the ReadXmlSchema method with the StreamReader object.
    thisDataSet.ReadXmlSchema(readStream)
    ' Close the StreamReader
    readStream.Close()
End Sub
注解
ReadXmlSchema使用 方法为 DataSet创建架构。 架构包括表、关系和约束定义。 若要将架构写入 XML 文档,请使用 WriteXmlSchema 方法。
XML 架构是使用 XSD 标准编写的。
注意
如果 msdata:DataType 和 xs:type 类型不匹配,则可能发生数据损坏。 不会引发异常。
在 ReadXmlSchema 调用 ReadXml 用于填充 DataSet的方法之前,通常会调用 方法。
从 类继承的 TextReader 类包括 StreamReader 和 StringReader 类。
注意
如果架构DataSet包含同一名称但类型不同的元素,则在同一命名空间中,则在尝试使用 ReadXmlSchema将架构读取到 时DataSet,将引发异常。 如果使用 .NET Framework版本 1.0,则不会发生此异常。
另请参阅
适用于
ReadXmlSchema(String)
- Source:
- DataSet.cs
- Source:
- DataSet.cs
- Source:
- DataSet.cs
从指定的文件中将 XML 架构读入 DataSet。
public:
 void ReadXmlSchema(System::String ^ fileName);public void ReadXmlSchema (string fileName);member this.ReadXmlSchema : string -> unitPublic Sub ReadXmlSchema (fileName As String)参数
- fileName
- String
从中读取的文件的名称(包括路径)。
例外
示例
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);
}
Private Sub ReadSchemaFromFile()
    ' Create the DataSet to read the schema into.
    Dim thisDataSet As New DataSet()
    ' Set the file path and name. Modify this for your purposes.
    Dim filename As String = "Schema.xml"
    ' Invoke the ReadXmlSchema method with the file name.
    thisDataSet.ReadXmlSchema(filename)
End Sub
注解
ReadXmlSchema使用 方法为 DataSet创建架构。 架构包括表、关系和约束定义。 若要将架构写入 XML 文档,请使用 WriteXmlSchema 方法。
XML 架构是使用 XSD 标准编写的。
注意
如果 msdata:DataType 和 xs:type 类型不匹配,则可能发生数据损坏。 不会引发异常。
在 ReadXmlSchema 调用 ReadXml 用于填充 DataSet的方法之前,通常会调用 方法。
注意
如果 DataSet 的架构在相同的命名空间中包含名称相同但类型不同的元素,则当您尝试使用 DataSet 将架构读入 ReadXmlSchema 中时将引发异常。 如果使用 .NET Framework版本 1.0,则不会发生此异常。
另请参阅
适用于
ReadXmlSchema(XmlReader)
- Source:
- DataSet.cs
- Source:
- DataSet.cs
- Source:
- DataSet.cs
public:
 void ReadXmlSchema(System::Xml::XmlReader ^ reader);public void ReadXmlSchema (System.Xml.XmlReader? reader);public void ReadXmlSchema (System.Xml.XmlReader reader);member this.ReadXmlSchema : System.Xml.XmlReader -> unitPublic Sub ReadXmlSchema (reader As XmlReader)参数
示例
以下示例创建一个新的 DataSet 和 System.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();
}
Private Sub ReadSchemaFromXmlTextReader()
    ' Create the DataSet to read the schema into.
    Dim thisDataSet As New DataSet()
    ' Set the file path and name. Modify this for your purposes.
    Dim filename As String = "Schema.xml"
    ' Create a FileStream object with the file path and name.
    Dim stream As New System.IO.FileStream _
       (filename, System.IO.FileMode.Open)
    ' Create a new XmlTextReader object with the FileStream.
    Dim xmlReader As New System.Xml.XmlTextReader(stream)
    ' Read the schema into the DataSet and close the reader.
    thisDataSet.ReadXmlSchema(xmlReader)
    xmlReader.Close()
End Sub
注解
ReadXmlSchema使用 方法为 DataSet创建架构。 架构包括表、关系和约束定义。
XML 架构是使用 XSD 标准编写的。
注意
如果 msdata:DataType 和 xs:type 类型不匹配,则可能发生数据损坏。 不会引发异常。
在 ReadXmlSchema 调用 ReadXml 用于填充 DataSet的方法之前,通常会调用 方法。
类 System.Xml.XmlReader 是抽象的。 继承自 XmlReader 的类是 System.Xml.XmlTextReader 类。
注意
如果架构DataSet包含同一名称但类型不同的元素,则在同一命名空间中,则在尝试使用 ReadXmlSchema将架构读取到 时DataSet,将引发异常。 如果使用 .NET Framework版本 1.0,则不会发生此异常。