Read XML data: function to load xml data to dataset (C#)

Rajni.Shekhar
Posted by Rajni.Shekhar under C# category on | Points: 40 | Views : 2282
public static DataSet LoadXMLDataToDataSet(string xmlString)
{
//creating a new DataSet
DataSet ds = null;

//check if the xmlString is not blank
if (String.IsNullOrEmpty(xmlString))
{
//stop the processing
return ds;
}

try
{
//create a StringReader object to read xml string
using (StringReader stringReader = new StringReader(xmlString))
{
//initializing DataSet
ds= new DataSet();

//load the StringReader to our DataSet
ds.ReadXml(stringReader);
}
}
catch (Exception ex)
{
//return null
ds= null;
throw ex;
}
return ds;
}

Comments or Responses

Login to post response