Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am handling/reading Excel workbook using VB.Net Code.
Everything goes OK if worksheet has less than 20000 rows, but if it is more than 20000 then it throws following exception.

InvalidCastException Occured
Conversion from type 'Object(,)' to type 'String' is not valid.


My problem is that why it works some time and does not other time?
What could be the potential problem??

Code looks like this:

uArea.Digits = CurrentRow.Columns(AREA_DIGIT).value 
uArea.ValidFrom = CurrentRow.Columns(VALID_FROM).value


EDIT: Could this be the reason that i need to expose or dispose excel object ? in that case , is it possible to dispose Excel object? OR can i use GC.Collect? Please Help.
Posted
Updated 14-Jan-13 4:21am
v2

1 solution

This error may actually have nothing to do with the size of the excel. One of the rows after row 20000 may have some data that may be of a different type. It will be worth doing a quick data validation of the Excel file.
 
Share this answer
 
v2
Comments
sajidali143 14-Jan-13 5:52am    
Thanks Abhinav S. The problem is some time the same piece of code can process more then 25,000 rows and some time just throws exception after 20,000.
While testing today it even throws exception after 6000 rows.

Main problem is why some time it works and some time it doesn't?

Thanks for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900