Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TableToCSV(TextWriter output,DataTable table) {
- string FLD_FMT = "{0},";
- foreach(DataColumn column in table.Columns) {
- output.Write(string.Format(FLD_FMT,column.ColumnName));
- }
- output.WriteLine();
- foreach(DataRow row in table.Rows) {
- foreach(DataColumn column in table.Columns) {
- object value = null;
- if(row.IsNull(column))
- value = "NULL";
- else
- value = row[column];
- output.Write(string.Format(FLD_FMT,value));
- }
- output.WriteLine();
- }
- }
- void TableToCSV(StringBuilder output,DataTable table) {
- string FLD_FMT = "{0},";
- foreach(DataColumn column in table.Columns) {
- output.AppendFormat(FLD_FMT,column.ColumnName);
- }
- output.AppendLine();
- foreach(DataRow row in table.Rows) {
- foreach(DataColumn column in table.Columns) {
- object value = null;
- if(row.IsNull(column))
- value = "NULL";
- else
- value = row[column];
- output.AppendFormat(FLD_FMT,value);
- }
- output.AppendLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment