Changing the value of an object

Christopher Jack 1,616 Reputation points
2021-04-16T11:10:35.953+00:00

Hi,

I am trying to change some column names after reading the into a system object from oracle

using

$SelectDataTable.Columns[3]=""
$SelectDataTable.Columns[9]=""

I am getting the following error

InvalidOperation: C:\Powershell Scripts\Protectreports.ps1:70:1
Line |
70 | $SelectDataTable.Columns[9]=''
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unable to index into an object of type "System.Data.DataColumnCollection".

Is it possible to change the attribute of that object?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2021-04-17T14:50:08.763+00:00

    Have you tried setting the column Caption property? (I don't have any way to test with Oracle.)

    https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn.caption?view=net-5.0

    When I have to deal with an object where I am unfamiliar with the methods and properties, I like to use Get-Member, Format-List and Format-Table to take a peek at the data that I'm dealing with.

    $SelectDataTable | Get-Member  
    $SelectDataTable.Columns | Get-Member  
    $SelectDataTable.Columns[0] | Format-List  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.