I have a file to dataset converter that uses the ExcelReader to convert a file into a dataset.

public class ConvertExcelFileToDataSet : IConvertAFileToDataSet
{
    public DataSet Convert(HttpPostedFileBase file)
    {
        return GetDataFromExcel(file.InputStream);
    }

    private DataSet GetDataFromExcel(Stream target)
    {
        var excelReader = ExcelReaderFactory.CreateOpenXmlReader(target);
        excelReader.IsFirstRowAsColumnNames = true;
        return excelReader.AsDataSet();
    }
}

When I get the dataset back I need to break it into smaller chunks. Lets say 5 chunks of datasets so that I can do things with them. I will keep researching while I wait.

有帮助吗?

解决方案

It really depends on what you mean when you say "so that I can do things with them". If you were doing the same thing with each 'chunk' then you could use PLINQ like so

void SomeMethod()
{
    var data = GetDataSet().Tables[0].AsEnumerable();

    var qry = from d in data.AsParallel()
            select d.Field<int>("YourField") * 2;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top