Write Rows from DataTable to Text File

前端 未结 6 1573
面向向阳花
面向向阳花 2021-02-14 11:31
public void GenerateDetailFile()
{
  if (!Directory.Exists(AppVars.IntegrationFilesLocation))
  {
    Directory.CreateDirectory(AppVars.IntegrationFilesLocation);
  }

          


        
6条回答
  •  时光说笑
    2021-02-14 12:06

    You need to write the columns from each DataRow. Currently you are writing the DataRow object that is dataRow.ToString() hence you get string name "System.Data.DataRow" of dataRow in your file

    foreach(DataRow row in table.Rows)
    {
     foreach(DataColumn column in table.Columns)
     {
      sw.WriteLine(row[column]);
     }
    }
    

提交回复
热议问题