class Program
{
static void Main(string[] args)
{
DataTable toExcel = test.Copy();
foreach (DataColumn column in toExcel.Columns)
{
Console.Write(column.ColumnName + ",");
}
Console.Write(Environment.NewLine);
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("d:\\test.txt");
string content = "";
foreach (DataRow row in toExcel.Rows)
{
for (int i = 0; i < toExcel.Columns.Count; i++)
{
Console.Write(row[i].ToString().Replace(",", string.Empty) + ",");
content += row[i].ToString().Replace(",", string.Empty) + ",";
file.WriteLine(content);
}
Console.Write(Environment.NewLine);
}
file.Close();
}
}