1)我做了一个Dataset.WriteToXml(内存流对象) 2)然后我创建一个XMLDocument对象 3)然后我是XMLDocument.Load(内存流对象)
我收到“未找到XML根命名空间”异常。
数据集XML是否不包含所需的命名空间?
感谢。
答案 0 :(得分:1)
您是否在尝试将内存流加载到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);
}