none
Returning objects from functions is confusing RRS feed

  • Allgemeine Diskussion

  • The following code is confusing. There is a function, which only returns the given parameter. When I call the Function with a Directory it works. But when I call the function with a SqlDataReader it doesn't.
    
    
    I use power shell 1.0.
    
    
    Can anybody tell me what is wrong?
    
    
    function test ($p) {
    
     return $p;
    
    }
    
    
    
    $x = (Get-ChildItem)[0];
    
    $x = test -p $x;
    
    
    
    if ($x -eq $null) {
    
     echo "this will not be shown";
    
    }
    
    
    
    $conn = New-Object System.Data.SqlClient.SqlConnection("Server=***;Database=***;Password=***;User ID=***;MultipleActiveResultSets=True;Workstation ID=sync_reader");
    
    $conn.Open();
    
    
    
    $cmd = New-Object System.Data.SqlClient.SqlCommand;
    
    $cmd.Connection = $conn;
    
    $cmd.CommandText = "SELECT * FROM dbo.TABLE_COLUMNS";
    
    $x = $cmd.ExecuteReader();
    
    
    
    if ($x -eq $null) {
    
     echo "this will not be shown";
    
    }
    
    
    
    $x = test -p $x;
    
    
    
    if ($x -eq $null) {
    
     echo "this will be shown";
    
    }
    
    
    
    $conn.Close();
    
    
    
    
    Montag, 15. November 2010 11:57

Alle Antworten

  • Hi,

    this is a German speaking forum. If you encounter issues continuing in German, please let me know so that I can forward the thread to our English Forums.

    ist das Problem noch aktuell? Welche Fehlermeldung kommt denn? Übrigens, deinen Code konnte ich erfolgreich testen (Server 2008 with PS v1) mit Windows Auth.

    Gruß,
    Andrei

    Mittwoch, 17. November 2010 11:57
    Moderator