DataSet Export CSV Format (ASP.NET, C #)
Author: Not
MSN: NOTKING@hotmail.com
Email: nots@sohu.com
This article refers to the following Microsoft .NET framework class library namespace: system.data; system.web.ui.webControls;
SUMMARY This article resolves the DataSet to the CSV format problem, export data in DataGrid to the CSV format
Export DataSet All Columns to CSV Format Traversing Dataset Tabletes Traversing Table Rows Traversing Rows Columns
Code ///
Foreach (DataBle TB in ds.tables) {data = tb.tablename "/ n";
// Write a list of Foreach (Datacolumn Column In Tb.columns) {Data = Column.columnName ",";} DATA = "/ N"; // Write Data Foreach (DataRow Row In Tb.Rows) {Foreach (DataColumn Column In Tb.columns) {Data = Row [Column] .tostring () ",";} DATA = "/ n";} DATA = "/ n";} Return Data;}
DataSet and DataGrid Issues Under the case where we use DataGrid to display the DataSet, only the columns we need are displayed, and the DataSet is not displayed, so it may only need to export the columns in the DataGrid when exporting into a CSV format.
This article works: Mark the columns you need to export in the DataSet, only the tagged columns are only exported.
Code ///
///
///
Example: Export.seTexport (DS. Vendor list view, Dg.columns);
String Data = Export.ExportCSV (DS);
String Temp = string.format ("attachment; filename = {0}", "exportData.csv"); response.clearheaders (); response.Appendheader ("Content-Disposition", Temp); Response.write (DATA); Response.end ();