I am trying a "very" simple task to output values of each rows from a DataSet
:
for ($i=0;$i -le $ds.Tables[1].Rows.Count;$i++)
{
Write-Host 'value is : ' + $i + ' ' + $ds.Tables[1].Rows[$i][0]
}
gives output ...
value is : +0+ +System.Data.DataSet.Tables[1].Rows[0][0]
value is : +1+ +System.Data.DataSet.Tables[1].Rows[1][0]
value is : +2+ +System.Data.DataSet.Tables[1].Rows[2][0]
value is : +3+ +System.Data.DataSet.Tables[1].Rows[3][0]
value is : +4+ +System.Data.DataSet.Tables[1].Rows[4][0]
value is : +5+ +System.Data.DataSet.Tables[1].Rows[5][0]
value is : +6+ +System.Data.DataSet.Tables[1].Rows[6][0]
How do i get the actual value from the column?
Here's a practical example (build a dataset from your current location):
$ds.Tables["tblTest"]
is an object that you can manipulate just like any other Powershell object:The PowerShell string evaluation is calling ToString() on the DataSet. In order to evaluate any properties (or method calls), you have to force evaluation by enclosing the expression in
$()
Additionally
foreach
allows you to iterate through a collection or array without needing to figure out the length.Rewritten (and edited for compile) -
The parser is having trouble concatenating your string. Try this:
Edit: Using double quotes might also be clearer since you can include the expressions within the quoted string: