Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Export to excel using aspose
Message
From
09/03/2011 10:38:01
 
 
To
09/03/2011 10:03:20
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01502896
Message ID:
01503033
Views:
38
>>>Do you know off hand is it possible to read in part of a datatable. So I could set the start point in the data import and the number of rows I want
>>
>>I see there's a Cells.ImportDataRow() method but I'd imagine calling that repeatedly might be slow. You could, I suppose, create a temporary table to pass to the ImportDataTable(). Ugly but would work:
       public DataTable GetPartTable(DataTable dt, int start, int rowCount)
>>        {
>>            int stop = start + rowCount;
>>            DataTable CloneTable = dt.Clone();
>>            for (int i = start ; i< stop ; i++)
>>            {
>>                CloneTable.ImportRow(dt.Rows[i]);
>>            }
>>            return CloneTable;
>>        }
Then:
DataTable tmp = GetPartTable(OriginalTable, 0, 65656);
(Needs some parameter checking.....)
>
>Do you think using a DataReader be better ?

I honestly don't know. If you were cloning the whole table then:
CloneTable.Load(dt.CreateDataReader());
might be quicker but where you have to loop to import a fixed number of rows I'm not sure. You could make the above a bit neater by:
     IEnumerable<DataTable> GetBlock(DataTable dt, int blockSize)
        {
            int i = 0;
            for (; i < dt.Rows.Count - blockSize; i += blockSize)
            {
                yield return GetPartTable(dt, i, blockSize);
            }
            yield return GetPartTable(dt, i, dt.Rows.Count - i);
        }
then:
foreach (DataTable dt in GetBlock(OriginalTable, 65536))
            {  Cells.Add(.....);  }
But my count calculation might need verifying :-{
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform