将具有100万条记录的数据表导出到CSV

时间:2018-12-02 13:03:50

标签: c# asp.net-mvc export-to-csv

我有一个C#数据表,其中包含大约一百万行和20列 我需要将此导出到csv,我尝试了字符串生成器,但页面仍在加载

$('a.dropdown-item').click(function(){
    var search_txt = $(this).text();
    $('.searchbox-input').val(search_txt);
  });

  $('.searchbox-input').focus(function(){
    $(this).val();
  });

页面继续加载,没有任何进展

1 个答案:

答案 0 :(得分:0)

我将在下面返回类似代码的StringWriter

       private StringWriter ExportDataTable(DataTable dt)
       {
            StringWriter writer = new StringWriter();

            string[] columnNames = dt.Columns.Cast<DataColumn>().Select(x => x.ColumnName).ToArray();
            writer.WriteLine(string.Join(",", columnNames));

            foreach(DataRow row in dt.AsEnumerable())
            {
                writer.WriteLine(string.Join(",", row.ItemArray.Select(x => x.ToString())));
            }
            return writer;

        }