Convert Data Table to XML
private static string ConvertDataTableToXML(System.Data.DataTable dtData)
{
DataSetdsData = new DataSet();
StringBuildersbSQL;
StringWriterswSQL;
stringXMLformat;
try
{
sbSQL = new StringBuilder();
swSQL = new StringWriter(sbSQL);
dsData.Merge(dtData, true, MissingSchemaAction.AddWithKey);
dsData.Tables[0].TableName = "SampleDataTable";
foreach(DataColumn col indsData.Tables[0].Columns)
{
col.ColumnMapping = MappingType.Attribute;
}
dsData.WriteXml(swSQL, XmlWriteMode.WriteSchema);
XMLformat = sbSQL.ToString();
returnXMLformat;
}
catch(Exception sysException)
{
throwsysException;
}
No comments:
Post a Comment
Thank you for visiting my blog