title: Creating hashtable of hashtables using primary key from SQL query result as hashtable key
body: <p>I have a decently sized resultset from a query, and I would like to convert them into a hashtable of hashtables, with each sub hashtable containing a row from the result set, and use the unique ID from each row as the key for the hashtable containing that row. So far I have tried this:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$query = "SELECT * FROM [TaskCentre_Staging].[dbo].[vw_IT_PriceList]"
  
  $command = $connection.CreateCommand()
  $command.CommandText = $query
  
  $result = $command.ExecuteReader()
  
  $table = New-Object "System.Data.DataTable"
  $table.Load($result)
  
  $hashtable = @{}
  
  foreach($line in $table)
  {
      $hashtable.Add($line.U_ProductID, $line)
  }
  
  $hashtable
  </code></pre>
  
  <p>But this results in something like the following:</p>
  
  <pre>1 System.Data.DataRow
  2 System.Data.DataRow
  3 System.Data.DataRow
  4 System.Data.DataRow
  5 System.Data.DataRow
  ...</pre>
  
  <p>How do I get this to work? I've tried looking for hpw to convert datatables to hashtables, but everything I've seen seems only work for a simple hashtable, not the hashtable within a hashtable result that I need.</p>