Tuesday, April 15, 2014

Convert DataTable to XML

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

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...