I have a simple "bug", but it seems that I cannot figure it out. I'm reading an excel file (.xls) using ExcelLibrary, and I have a Do Loop, to go through my file. At the end of the file (my last row with data), the condition should be true and the loop should stop. Here is my issue: I get this error when the loop reaches my last row : "System.NullReferenceException: Object reference not set to an instance of an object."
Here is my code:
Try
Do Until TryCast(WS.Cells(ws_Row, 2).Value.ToString, String) = Nothing
' Get data into a data table
ws_Row = ws_Row + 1
Loop
Catch ex As Exception
LBL_ERR.Text = ex.ToString
LBL_ERR.ForeColor = System.Drawing.Color.Red
Exit Sub
End Try
This should be so simple to accomplish, yet I get this error message PS. The error I receive is at the row with the Do Until row