首页 > 其他分享 >DataTableToXml

DataTableToXml

时间:2023-02-07 17:47:45浏览次数:36  
标签:Count string int DataTableToXml table xmlStr Columns

private static string DataTableToXml(DataTable table)
        {
            if (null == table) return string.Empty;
            string xmlStr = "<ROOT>\n";
            for (int i = 0; i < table.Columns.Count; i++)
            {
                xmlStr += "<DATA_HEADER><DATA_NAME>" + table.Columns[i].ColumnName + "</DATA_NAME><DATA_TYPE>" + table.Columns[i].DataType + "</DATA_TYPE></DATA_HEADER>\n";
            }
            for (int i = 0; i < table.Rows.Count; i++)
            {
                xmlStr += "<DATA_BODY>\n    ";
                for (int j = 0; j < table.Columns.Count; j++)
                {
                    xmlStr += "<" + table.Columns[j].ColumnName + ">" + table.Rows[i][j] + "</" + table.Columns[j].ColumnName + ">";
                }
                xmlStr += "\n</DATA_BODY>\n";
            }
            xmlStr += "</ROOT>";
            return xmlStr;
        }
View Code

 

标签:Count,string,int,DataTableToXml,table,xmlStr,Columns
From: https://www.cnblogs.com/songjiali/p/17099266.html

相关文章