How to export a DataTable to Xml with ALL columns as attributes?

前端 未结 5 1632
执笔经年
执笔经年 2020-12-31 18:58

Question: I\'m exporting a System.Data.DataTable to XML. So far it works fine. But I want to have all the data in attributes, which works fine as well. But my problem now, i

5条回答
  •  既然无缘
    2020-12-31 19:31

    Try setting the column DefaultValue to something valid

    foreach (DataTable dt in ds.Tables) {
    
            foreach (DataColumn dc in dt.Columns) {
                dc.ColumnMapping = MappingType.Attribute;
               //If type is DataType string
               dc.DefaultValue = String.Empty;
            }
    

提交回复
热议问题