2017-02-15 6 views
0

DataGridView에서 .txt 파일로 데이터를 내보내는 데 문제가 있습니다. 내가있는 gridview (350K 이상 기록)에 데이터베이스에서 빅 데이터를 다운로드하고 난 "에서 OutOfMemoryException"를 얻을 약 200K 기록 후, txt 파일로 내보낼 때DataGridView C#의 수출자

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.IO; 

namespace TSQ 
{ 
    class TxtExporter : IExporter 
    { 
     public void Export(DataGridView dataGrid, Output output) 
     { 
      if (output == null) 
       return; 

      string filePath = output.TemplatePath; 

      try 
      { 
       using (StreamWriter sw = new StreamWriter(filePath)) 
       { 
        for (int row = 0; row < dataGrid.Rows.Count; row++) 
        { 
         for (int col = 0; col < dataGrid.Columns.Count; col++) 
         { 
          sw.Write(dataGrid[col, row].Value.ToString()); 
          sw.Write('\t'); 
         } 
         sw.WriteLine(); 
         //sw.Flush(); <- also doesn`t work if uncommented 
        } 
       } 
      } 
      catch (Exception) 
      { 
       //MessageBox.Show(exc.Message); 
       throw; 
      } 
     } 
    } 
} 

... 당신이 어떤이 있습니까 DataGridView에서 큰 데이터를 내보내는 방법 아이디어? 이 .txt 인 수없는 경우

안부, 마이클

+0

은 대신 텍스트 파일에 해당 문자열을 쓸에서는 StreamWriter를 사용하여 다음 DataGridView를 통해 반복과) (A의 StringBuilder에 내용을 저장하고, 시도? –

+1

[C# Windows Form의 DataGridView에서 텍스트 파일에 쓰기] 가능한 복제본 (http://stackoverflow.com/questions/19311535/writing-to-a-text-file-from-datagridview-in-c-sharp- windows-form) –

+0

클립 보드로 시도했지만 속도가 느려지고 메모리 부족 오류도 발생합니다. ( – Roofy

답변

0

대신 Excel로 수출하려고합니다. 참고 How to Export DataGridView Data to Excel by using Excel Object

+0

이 순간 나는 Excel로 내보낼 수있는 옵션이 있습니다.이 "ExcelExporter"에 다른 클래스를 사용하고 있습니다. 많은 시간이 걸리고 큰 데이터 (> 100K)로 인해 OutOfMemoryException이 발생합니다. – Roofy