Rahul Sharma
Rahul Sharma

Reputation: 190

Writing 100 rows form oracle database using powershell

I have an problem using powershell . first i would like to explain what the sitiation is :

I have an Oracle database running with an table NAMES . In the table i got about 10000 rows with data . I would like to to count them til 100 rows and and then "echo " them on my powershell prompt here is where the problem comes in because i can count the rows using the following script:

  $query = “SELECT * FROM NAMES"
            $command = $con.CreateCommand()
            $command.CommandText = $query
            $result = $command.ExecuteReader()
           $test= $result|Measure-Object



$i=$test.Count

The number that returns is the correct number but then it goes wrong because when i want to use an foreach loop i cant get the names from my table

Here is wat i got maybey it helps

foreach ($Row in $query.Tables[0].Rows)
{ 
  write-host "value is : $($Row[0])"
}

hope someone finds an answer

Upvotes: 0

Views: 172

Answers (1)

vonPryz
vonPryz

Reputation: 24081

You are missing the strict mode: Set-StrictMode -Version latest. By setting it, you'd get much more informative an error message:

$query = "SELECT * FROM NAMES"
foreach ($Row in $query.Tables[0].Rows) { ... }
Property 'Tables' cannot be found on this object. Make sure that it exists.
+ foreach ($Row in $query.Tables[0].Rows) { ... }

The $query variable doesn't contain member Tables, so attempting to read it is futile. It would seem likely that the $result variable contains the Tables member. That depends on the data provider you are using and what's missing on the code sample.

Upvotes: 1

Related Questions