How to serialize a DataTable to a string?

前端 未结 4 1315
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 08:47

Recently I was in the need to serialize a DataTable as a string for further processing (storing in a file).

So I asked myself: How to serialize a DataTa

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 09:26

    You can also do this.

    DataTable dt = new DataTable()  
    //... Fill Datatable from SQL or a thousand other places you have seen on the net.     
    Response.ContentType = "text/xml";    
    dt.WriteXml(Response.OutputStream);  
    Response.Flush();
    Response.End();
    

    Documentation found at

    http://msdn.microsoft.com/en-us/library/system.data.datatable.writexml(v=VS.100).aspx

提交回复
热议问题