Link to home
Start Free TrialLog in
Avatar of jfsedlar3rd
jfsedlar3rdFlag for United States of America

asked on

Datareader error: Object reference not set to an instance of an object.

I am writing an ASP.NET application. I am using a data reader object the way the code flows is that sometimes it gets instantiated and sometimes it doesnt. This is causing some issues because I am using a data reader multiple times in a subroutine so I have to close it before I can create a new one. However if it skips over the code that instantiates it when it hits the code to check if its open:
If Not dReader.IsClosed Then
                        dReader.Close()
                    End If

I am getting an error. System.NullReferenceException: Object reference not set to an instance of an object. Does anyone know how to check if this object has been instantiated already?
ASKER CERTIFIED SOLUTION
Avatar of ChetOS82
ChetOS82
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jfsedlar3rd

ASKER

Thank you for the timely response it works great! A++