WriteXml & XmlDataDocument questions

J

Jamie Owens

Hi everyone,

I have a question regarding DataSets and the WriteXml method.
Specifically, I'm having trouble writing out my DataSet, then reading the
contents back in to an XmlDataDocument.

For instance, my code reads like this:

/////////////////////////

StringWriter l_strWrite = new StringWriter();
XmlDataDocument l_XMLDocument = new XmlDataDocument();

//MyDataSet is a pre-existing DataSet
MyDataSet.WriteXml(l_strWrite,System.Data.XmlWriteMode.WriteSchema);
l_XMLDocument.LoadXml(l_strWrite.ToString());

////////////////////////

No errors when I run this, however when all is said and done, my
XmlDataDocument's DataSet member has zero tables, whereas the original
("MyDataSet") has one table in its collection. Something's not right--
maybe I'm not saving the DataSet correctly via WriteXml()?

I realize the XmlDataDocument class has a DataSet member that I can assign
to, however in my code I can't just simply set things equal to
MyDataSet....I'm trying to write out the DataSet to a string then pass it
around from one section of my program to another. Only later on will I
create my XmlDataDocument.

Maybe I should create a temporary DataSet from my string when the time
comes, then assign it to my XMLDataDocument's DataSet member? Sounds like a
hack, but maybe it's an option. I don't know.

If you have any suggestions or ideas on how I can correctly write out/read
in my DataSet to an XMLDataDocument, I'd be glad to hear them. Thanks very
much.

-Jim
 
V

Val

Hi Jamie,
I think you have to use
/////////////
UrDataSet.ReadXml(<source>,System.Data.XmlReadMode.<mode>);
/////////////
instead of LoadXml to load the dataset back in.
Val
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top