Click here to Skip to main content
12,828,476 members (47,088 online)
Click here to Skip to main content
Add your own
alternative version


34 bookmarked
Posted 18 May 2005

Convert XML Data to DataSet and Back

, 18 May 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
This article describes the functions to convert the XML data to an untyped dataset and get the XML back from untyped dataset

Using the Code

Use this function to save an XML string to DataSet:

// Function to convert passed XML data to dataset
 public DataSet ConvertXMLToDataSet(string xmlData)
  StringReader stream = null;
  XmlTextReader reader = null;
   DataSet xmlDS = new DataSet() ;
   stream = new StringReader(xmlData);
   // Load the XmlTextReader from the stream
   reader = new XmlTextReader(stream);
   return xmlDS;
   return null;
   if(reader != null) reader.Close();
 }// Use this function to get XML string from a dataset

 // Function to convert passed dataset to XML data
 public string ConvertDataSetToXML(DataSet xmlDS)
  MemoryStream stream = null;
  XmlTextWriter writer = null;
   stream = new MemoryStream();
   // Load the XmlTextReader from the stream
   writer = new XmlTextWriter(stream, Encoding.Unicode);
   // Write to the file with the WriteXml method.
   int count = (int) stream.Length;
   byte[] arr = new byte[count];
   stream.Seek(0, SeekOrigin.Begin);
   stream.Read(arr, 0, count);
   UnicodeEncoding utf = new UnicodeEncoding();
   return utf.GetString(arr).Trim();
   return String.Empty ;
   if(writer != null) writer.Close();


  • 18th May, 2005: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

S Sansanwal
Australia Australia
No Biography provided

You may also be interested in...


Comments and Discussions

Answerthis is Single line code Pin
venki Livestrong15-Feb-15 22:47
membervenki Livestrong15-Feb-15 22:47 
Questionthere is a Simple two line peice of code to do this Pin
venki Livestrong15-Feb-15 23:13
membervenki Livestrong15-Feb-15 23:13 
GeneralGeneral Pin
hjhjhjhjhjhjhjhjh9-Oct-12 21:50
memberhjhjhjhjhjhjhjhjh9-Oct-12 21:50 
QuestionNon Standard Xml Pin
hussain2luv28-Apr-08 6:32
memberhussain2luv28-Apr-08 6:32 
Generalthankyou Pin
Xp3ll3d13-Nov-05 20:36
memberXp3ll3d13-Nov-05 20:36 
GeneralMuch Simpler Pin
Wasia10-Nov-05 10:55
memberWasia10-Nov-05 10:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 18 May 2005
Article Copyright 2005 by S Sansanwal
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid