title: How to assign datareader data into generic List ( of T )
body: <p>I would like assign datareader data into generic List ( of T ).</p>
  
  <p>I do not want to read the specific column item name. I want to make it dynamic.</p>
  
  <p>Example code:</p>
  
  <pre><code>Shared Function FormatUserList(ByVal PoReader As OracleDataReader) As List(Of Users)
      Dim oUserList As New List(Of Users)()
      Dim oUser As Users
      Dim dt As New DataTable
      dt = PoReader.GetSchemaTable()
  
      Do While PoReader.Read()
          Dim index As Integer = 0
          oUser = New Users()
  
          oUser.LoginId = Convert.ToString(PoReader("LoginId"))
          oUser.Password = Convert.ToString(PoReader("Password"))
          oUser.FirstName = Convert.ToString(PoReader("FirstName"))
          oUser.LastName = Convert.ToString(PoReader("LastName"))
          oUser.NRIC = Convert.ToString(PoReader("NRIC"))
          oUser.MobileNo = Convert.ToInt64(PoReader("MobileNo"))
          oUser.Address = Convert.ToString(PoReader("Address"))
          oUser.Zip = Convert.ToInt64(PoReader("Zip"))
          oUser.State = Convert.ToInt64(PoReader("state"))
          oUser.UserGroupId = Convert.ToInt64(PoReader("UserGroupId"))
          oUser.CompanyId = Convert.ToInt64(PoReader("CompanyId"))
          oUser.Active = Convert.ToInt64(PoReader("Active"))
          oUserList.Add(oUser)
      Loop
  
      Return oUserList
  End Function
  </code></pre>
  
  <p>I need something like below, but I receive an error when looping the 2nd row data to <code>SetValue</code>.</p>
  
  <p>"Object reference not set to an instance of an object."</p>
  
  <pre><code>Do While PoReader.Read()
  
    oUserGroup = New UserGroups()
  
    Dim type As Type = GetType(UserGroups) 
    Dim obj As Object = Activator.CreateInstance(type)
  
      For Each row As DataRow In dt.Rows
          sColName = row.Field(Of String)("ColumnName")
          type.GetProperty(sColName).SetValue(obj, PoReader(row.Field(Of String)("ColumnName")), Nothing)
          oUserGroupList.Add(obj)
      Next row
  Loop
  </code></pre>