Every once in awhile, you come across this exception: System.Null Reference Exception – “Object reference not set to an instance of an object.” You see people asking about this everywhere; about why are they getting this error. Note, regardless of the scenario, the cause is always the same in .Net: You are trying to use a reference variable who’s value is Nothing/null.When the value is Nothing/null for the reference variable, that means it is not actually holding a reference to an instance of any object that exists on the heap. Net, you are trying to access a string that has not been initialized. You can’t even compile code like the following in C# Remember, a string is a reference type (a character array) that has to have a value.
The Get Orders function inside of Customers requires an instance of a connection, but you disposed of the required objects required to access the database back up in Load Data() when you called a. Be careful when you clean up your instances, that you are not using them again somewhere.This is most common in classes where you are using class-wide instantiated objects.If you create and drop your objects within each method, this isn’t going to be a problem, and you are actually following a better guideline by creating at the last necessary moment, and destroying at the first possible moment, not to mention avoiding possible exceptions like Invalid Reference Exception.objects, see Data Sets, Data Tables, and Data Views.Whereas Data Table objects contain the data, the Data Relation Collection allows you to navigate though the table hierarchy.The tables are contained in a Data Table Collection accessed through the property.