c# - How to write a XML file using dataset having multiple table with the help of XmlWriter? -


I am using a dataset and storing a query result in that data set. My question id is such that

  string query = @ "SELECT * FROM TABLE1; SELECT * FROM TABLE2; SELECT * FROM TABLE3;";  

I am using the following things:

  XmlDocument relationSheepDoc = New XmlDocument (); Stringwriters sWriter = new stringwriter (); XmlTextWriter xmlWriter = new XmlTextWriter (sWriter); Dataset odetasset = new dataset ("relationship"); ODataSet = sql.ExecuteSqlDataSet (query); String fileContent = string.Empty; For (int i = 0; i & lt; oDataSet.Tables.Count; i ++) {oDataSet.Tables [i] .WriteXml (xmlWriter, XmlWriteMode.WriteSchema); FileContent = sWriter.ToString (); } RelationSheepDoc.LoadXml (fileContent); XmlWriter.Close (); Return Relationships Doc;  

It only writes the first table and produces an exception how can I write all the three tables in a single XML file? Please help me ...

You should write the whole dataset at a time, such as:

oDataSet.WriteXml (xmlWriter, XmlWriteMode.WriteSchema);

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -