Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 13-Jan-13 23:27pm
Edited 14-Jan-13 5:21am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
sajidali143 at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100