Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 3 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
I would like to add a calculated field to a table I've pulled from a database. I'm using "| Select @{" to build a custom object with a calculated field. I call it the object $x. But when I sent it to ConvertTo-DataTable function it throws an error. Though Out-GridView works fine with $x. How do I build $x properly so it can be attached to $datagridview1?
$x = $dataset.Tables[0] | select *, @{ n = "calculated_field"; e = { "$($_.calculated_field) test" } } -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors, name
$datagridview1.DataSource = $x
$x | Out-GridView
In other words, after building a custom object with select *, @{ n = I can't throw it into $datagridview1 as it would display nothing.
As for adding calculated field using SQL SELECT statement. Imagine there is part of a data in MS Access database and another part in Active Directory. I can't merge them in a single SQL SELECT statement, can I?
Thanks, I've got the idea. The solution where I create a temporary field in SQL Select statement and then alter it in ForEach-Object cycle is acceptable. Though the sample doesn't work. $rdr doesn't have load method. It seems one suppose to $dt.load($rdr)
This topic is 3 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.