Home All Groups Group Topic Archive Search About

NullReference Exception while iterating through array of DataRows

Author
8 Mar 2007 9:58 AM
aparnaum
Hi,

I need your help on the scenario mentioned below. Please advise.

Sincere Regards,
Aparnaa M Kulkarnii

Scenario


I am iterating through an array of DataRow objects using the For
loop.
e.g. If dtRows() is the array of dataRows then I have something like


' This is the Code snippet inside a Function called say DoProcessing
========================================

Dim i As Integer
Dim dRow As DataRow

Line 1     For i=0 to dtRows.Length - 1
Line 2     dRow = dtRows(i)
Line x     ' Use dRow to do a lot of processing here
Line n     Next
========================================
I am getting an Object Reference not set to an instance...error. At
the Line 2 above for one of the dataRows.
e.g. The total length of dtRows array  was 1153. I got an error at row
number 666.

Further I have introduced the try catch block inside the for loop as
follows:

========================================
Dim i As Integer
Dim dRow As DataRow

Line 1     For i=0 to dtRows.Length - 1
Line 2    Try
Line 3     dRow = dtRows(i)
Line x     ' Do a lot of processing here
    Catch ex
      ConverttoDataSet(dtRows)
    End Try
Line n     Next

========================================

Now when I get the exception I have tried writing the dataRows to a
dataset and saved the dataset as an XML file. On checking the saved
xml file I found that record number 666 does not seem to have any
problem and infact the dataset xml has printed all 1153 records. I am
failing to understand the reason for getting a NullReference Exception
at the point mentioned. Further more this error is not consistent.
Do you need more inputs to analyse this problem? Any answers on this
one would be really very very helpful.

Thanks !

AddThis Social Bookmark Button