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)
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
$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
I'd like to use the column name if possible, too.
Any pointers?
thanks, Sylvia