xml output from sql query

  • I picked 2 fields in the table and it displayed them:

     

    System.Data.DataRow

    11-371517-582-3-02 2VAK

  • Bruin wrote:

    I picked 2 fields in the table and it displayed them:

    System.Data.DataRow 11-371517-582-3-02 2VAK

     

    Well, it displayed one of them. It is telling you that one of the "fields" is a  System.Data.DataRow object which needs to be expanded. Here's a page about this: https://newbedev.com/extract-data-from-system-data-datarow-in-powershell

    Ultimately you have to get to a place where you are able to output the data that you are expecting to see rather than an indicator of an object, as above. Once you are at that point then you can write it out.


    I'm on LinkedIn

  • It produced 2 fields from the select

     

    11-371517-582-3-02   1st value

    2VAK      2nd value.

    Sorry I guess I'm confused.

    Thx.

  • So the issue is still that your evaluation is saying you have no rows? Or is is something else? If the former have a look at the answers on the following page and see if they help. Failing that, do an internet search for working with sql data in powershell and the System.Data.DataRow object class.

    https://stackoverflow.com/questions/15395510/returning-a-row-count-for-a-datarow-in-powershell

     


    I'm on LinkedIn

  • Correct in original script... It falls thru to:

     

    # Message stating no data to export.

    Write-Host "There is no data to export."

    Thanks.

     

     

  • Bruin wrote:

    Correct in original script... It falls thru to:

    # Message stating no data to export. Write-Host "There is no data to export."

    Thanks.

     

    Did you look at the link I sent? Try all of the options there?


    I'm on LinkedIn

  • Okay got it working from the links:

     

    Used:

    if ($items -ne $null)

    Now I have output...

    Thanks Again!!!!

  • When It creates the XML output how can I get the encoding to be utf-8?

    This is all I'm seeing at the TOP:

     

    <?xml version="1.0"?>

    Thx.

     

  • You need to specify your encoding, at the moment you are encoding using $Null. So change this:

    # Create the XML file.
    $xmlWriter = New-Object System.XMl.XmlTextWriter($fullFilePath,$Null)

     

    To this:

    # Create the XML file.

    $encoding = [System.Text.Encoding]::UTF8
    $xmlWriter = New-Object System.XMl.XmlTextWriter($fullFilePath,$encoding)

     

    • This reply was modified 3 years, 1 month ago by  PB_BI.


    I'm on LinkedIn

  • Cool thanks!!!!!

Viewing 10 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic. Login to reply