title: Getting data from SQL Server 2008 with Powershell
body: <p>I'm having some difficulties getting data from a simple stored procedure in SQL Server working.  I have a Powershell script that needs to get variables filled from 3 columns (the procedure just returns 1 row)</p>
  
  <p>Here's what I have that isn't working.  Somehow I'm not referencing the column value correctly.  I've tried various methods, but usually get the error "Cannot index into a null array".  I don't want to iterate through the resultset, I just want to directly set some values from the one row returned into variables</p>
  
  <pre><code>$conn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
  $conn.ConnectionString = `
    "Server=ServerName;Database=ShopDB;Integrated Security=True"
  $sqlQuery = new-object System.Collections.Specialized.StringCollection
  $sqlQuery.Add("JobSettingsGet")
  $Resultset = $conn.ExecuteWithResults($sqlQuery)
  
  # $UserName = $table.Rows(0).Columns(0) 
    # error - Method invocation failed because [System.Data.DataTable] doesn't 
    # contain a method named 'Rows'.
  # $UserName = $table.Rows[0].Columns[0] 
    # error - cannot index null array
  # $UserName = $table.Row(0).Column(0) 
    # error - Cannot index into a null array,  also Method invocation failed 
    # because [System.Data.DataTable] doesn't contain a method named 'Row'.
  # $UserName = $table.Rows[0].Columns[1].Value 
    # error - cannot index null array
  </code></pre>
  
  <p>I'd like to use the column name if possible, too.</p>
  
  <p>Any pointers?  </p>
  
  <p>thanks,
  Sylvia</p>