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);
}