gpt4 book ai didi

xml - DataSet.WriteToXml 中缺少根命名空间

转载 作者:行者123 更新时间:2023-12-04 17:05:10 24 4
gpt4 key购买 nike

1)我做了一个Dataset.WriteToXml(内存流对象)
2)然后我创建一个 XMLDocument 对象
3)我然后XMLDocument.Load(内存流对象)

我收到“找不到 XML 根命名空间”异常。

数据集 XML 是否不包含所需的命名空间?

谢谢。

最佳答案

您是否在尝试将内存流加载到 XmlDocument 之前重新定位它?

DataSet ds = new DataSet();
using (SqlConnection connection = new SqlConnection("some connection string"))
using (SqlCommand command = new SqlCommand("select * from mytable", connection))
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.Fill(ds);
}

XmlDocument xml = new XmlDocument();
using (Stream stream = new MemoryStream())
{
ds.WriteXml(stream);
// We must reposition the memory stream before loading the xml
stream.Position = 0;
xml.Load(stream);
}

关于xml - DataSet.WriteToXml 中缺少根命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/469341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com