Reputation: 193
I read an excel file and put it in a Datatable
.
If I put a breakpoint and inspect the value of myDatatable.Rows.Count()
it is equal to the number of rows in my excel file.
But then I pass my datatable object to a method like this:
private void Foo(Datatable dt)
{
DataTableReader reader = dt.CreateDataReader();
while(reader.Read())
{
// do stuff on each row
}
}
Now if I put a counter inside my while loop
, it shows for example 10 while the number of rows are really 100000.
What is it I am doing wrong?
Upvotes: 1
Views: 797
Reputation: 554
That should work similar to a for-each
loop on DataTable.Rows
I am guessing somewhere in your while loop
you are exiting out of the loop. Make sure you have used "break
" and "continue
" correctly.
Upvotes: 1
Reputation: 896
What makes you think anything's wrong? The table will have e.g. 100000 rows, that won't change. The DataReader, iterating over the table one row at a time, will have a different position on each iteration.
Upvotes: 0