1

I have just started learning asp.net with c# and want to know how to write datasets to XML using asp.net. Can anyone provide me any example or reference so that I can move ahead.

Thanks in Advance

Anu Sharma

2 Answers 2

1

The WriteXml method will save the entire dataset to an xml file or stream.

myDataset.WriteXml("dataset.xml", XmlWriteMode.WriteSchema);
Sign up to request clarification or add additional context in comments.

Comments

0

Create one empty data dataset with database name, so that this name will reflect to your converted xml document

DataSet ds = new DataSet();
ds.DataSetName = "ds";

Add your data (data tables) to this dataset with name

data.TableName = "tb";
ds.Tables.Add(data);

Create one XmlDocument & load data string into it

using (MemoryStream memoryStream = new MemoryStream())
{
    using (TextWriter streamWriter = new StreamWriter(memoryStream))
    {
        XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataSet));
        xmlSerializer.Serialize(streamWriter, ds);
        result = Encoding.UTF8.GetString(memoryStream.ToArray());
    }
}

XmlDocument _doc = new XmlDocument();
_doc.LoadXml(result);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.