This is actually found in the documentation in the section Writing to a CSV using a DataTable .
I will also give an example code.
using( var dt = new DataTable() ) { dt.Load( dataReader ); foreach( DataColumn column in dt.Columns ) { csv.WriteField( column.ColumnName ); } csv.NextRecord(); foreach( DataRow row in dt.Rows ) { for( var i = 0; i < dt.Columns.Count; i++ ) { csv.WriteField( row[i] ); } csv.NextRecord(); } }
The headers are not something special or different in the CSV file.
Josh close
source share