title: Populate an Array of Object Based on DataReader Data
body: <p>I am not sure how to phrase my question properly but I want to achieve something like this.</p>
  
  <p>I have a class named Products</p>
  
  <pre><code>public class Products
  
  private ID as Integer
  
  private Name as String
  
  Public Property ProductID()
    Get
      Return ID
    End Get
    Set(ByVal value)
      ID = value
    End Set
  End Property
  </code></pre>
  
  <p>In one of my code behind pages, I am retrieving data from an SQL Command and placing the same into a datareader object.</p>
  
  <p>How would I be able to declare the class so that each row in my datareader would actually be an instance of the said class?</p>
  
  <p>Like for example:</p>
  
  <pre><code>Dim myProduct() as New Product
  Dim intCnt as Integer 
  
  While datareaderData.read()
    intCnt += 1
    myProduct(intCnt) = new Product
    myProduct(intCnt).ID = datareaderData("ID")
    myProduct(intCnt).Name = datareaderData("Name")
  End While
  </code></pre>
  
  <p>When I do the same, I am getting an error "Object Reference Not Set to an Instance of an Object.</p>
  
  <p>I am quite stumped on this one. Any tips greatly appreciated.  Thanks.</p>