OutOfMemoryException while trying to read big Excel file into DataTable

前端 未结 1 751
忘了有多久
忘了有多久 2021-01-20 16:40

I\'m using SSIS package to clean and load data from .Xlsx file to SQL Server table. I have also to highlight cells containing wrong data in .Xlsx file, for this I have to g

1条回答
  •  醉梦人生
    2021-01-20 17:05

    When trying to read data from an Excel with huge number of Rows, it is better to read data by chunk (in OleDbDataAdapter you can use paging option to achieve that).

    int result = 1;
    int intPagingIndex = 0;
    int intPagingInterval = 1000;
    
    while (result > 0){
    
        result = daGetDataFromSheet.Fill(dsErrorColumns,intPagingIndex, intPagingInterval , Error_Sheet);
        System.Data.DataTable dtErrorColumns = dsErrorColumns.Tables[Error_Sheet];
    
        //Implement your logic here
    
        intPagingIndex += intPagingInterval ;
    
    }
    

    This will prevent an OutOfMemory Exception. And no more need to specify a range like AC1:AC10000

    References

    • Paging Through a Query Result
    • Fill(DataSet, Int32, Int32, String)

    0 讨论(0)
提交回复
热议问题