datable转xml

  /// <summary>
/// datatable转换xml
/// </summary>
/// <param name="xmlDS"></param>
/// <returns></returns>
public static string ConvertDataTableToXML(DataTable xmlDS)
{
StringBuilder strXml = new StringBuilder();
strXml.AppendLine("<MonitorData>");
for (int i = 0; i < xmlDS.Rows.Count; i++)
{
strXml.AppendLine("<" + xmlDS.TableName + ">");
for (int j = 0; j < xmlDS.Columns.Count; j++)
{
strXml.AppendLine("<" + xmlDS.Columns[j].ColumnName + ">" + xmlDS.Rows[i][j] + "</" + xmlDS.Columns[j].ColumnName + ">");
}
strXml.AppendLine("</" + xmlDS.TableName + ">");
}
strXml.AppendLine("</MonitorData>"); return strXml.ToString();
}

  

上一篇:使用ADO对象添加、修改、删除数据


下一篇:UICollectionView中Cell左对齐 居中 右对齐 等间距------你想要的,这里都有