C# 数据表c的表架构#

C# 数据表c的表架构#,c#,C#,如何将模式读入c中的datatable# 您的代码将引发“根元素丢失”异常 我在中找到了一个解决方案,即添加以下代码以重置位置 System.IO.MemoryStream xmlStream = new System.IO.MemoryStream(); StreamWriter writer = new StreamWriter(xmlStream); writer.Write(data); writer.Flush(); xmlStream.Posi

如何将模式读入c中的datatable#

您的代码将引发“根元素丢失”异常

我在中找到了一个解决方案,即添加以下代码以重置位置

    System.IO.MemoryStream xmlStream = new System.IO.MemoryStream();
    StreamWriter writer = new StreamWriter(xmlStream);
    writer.Write(data);
    writer.Flush();
    xmlStream.Position = 0;//Add this to reset the position of the stream.

请再试一次。

当你说失败时,你的确切意思是什么?它会引发异常吗?它读取模式的一部分吗?它会无声地崩溃吗,等等。你太棒了,这正是我得到的错误,将位置设置为0就成功了。谢谢
 public static Stream StringToStream(string data)
 {
     try
     {
        System.IO.MemoryStream xmlStream = new System.IO.MemoryStream();
        StreamWriter writer = new StreamWriter(xmlStream);
        writer.Write(data);
        writer.Flush();
        return xmlStream;
     }
     catch (Exception)
     {
         return null;
     }
 }

table.ReadXmlSchema(StringToStream(saveData));
    System.IO.MemoryStream xmlStream = new System.IO.MemoryStream();
    StreamWriter writer = new StreamWriter(xmlStream);
    writer.Write(data);
    writer.Flush();
    xmlStream.Position = 0;//Add this to reset the position of the stream.