0

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

1
  • Wouldn't you want to iterate over $result rather than $query? Commented Nov 3, 2014 at 12:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.