How to iterate through a get-sqldata resultset

rated by 0 users
This post has 2 Replies | 2 Followers

Not Ranked
Posts 6
stiej1977 Posted: 11-01-2011 6:26 AM

how do i iterate through a resultset obtained from using the SQLPSX get-sqldata? I want to output the resultset to an excel file. i'm ok with creating the excel file.

thanks

Top 10 Contributor
Posts 658
Idera Employee

SQLPSX get-sqldata returns an ADO.Net DataTable. One way to iterate we be to use a ForEach like this:

$tbl = get-sqldata ...

foreach ($row in $tbl) {

  $($row.Field)

  ...

}

Enclosing the field in a $( ) ensures you get the underlying data primitive.

Not Ranked
Posts 6

That's what I wanted to hear! thanks so much. I've spent hours and hours messing round with different ways. just couldn't work out why $row.Field by itself didn't work. Didn't know about this $(....) thing.

 

thanks a lot

Steve

Page 1 of 1 (3 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.