views:

199

answers:

1

Hi,

1) I do a Dataset.WriteToXml(memory stream object) 2) Then i create a XMLDocument object 3) I then XMLDocument.Load (memory stream object)

I get a "XML Root namespace not found" exception.

Does the Dataset XML not include the required namespace ?

Thanks.

+1  A: 

Are you repositioning your memory stream before trying to load it into the 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);
}
Darin Dimitrov