Hi there,
I am fairly new to Powershell and Powershell Studio. I am writing a script that connects out to a SQL database, and then returns a Dataset, and then I am trying to use a piece of this dataset to populate a list box, but instead of the nice computer names, I am getting @{Name=ComputerName} for each line instead of just Computer Name
SQL Connection Code
Using the Dataset Data to fill Listbox
If someone could help with why I am getting this result, I would appreciate it!
Results
Data Loading into my Listbox does not look correct
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.
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.
Re: Data Loading into my Listbox does not look correct
Don't use select at teh end of teh where filter.
Call the listbox like this;
Load-ListBox $Listbox1 $names 'Name'
DO not enumerate in a for just hand the data set.
Listboxes are data capable so you can just assign the datatable as the data source and use the listbox data specs to assign the field to diaplay and teh field to return,
Call the listbox like this;
Load-ListBox $Listbox1 $names 'Name'
DO not enumerate in a for just hand the data set.
Listboxes are data capable so you can just assign the datatable as the data source and use the listbox data specs to assign the field to diaplay and teh field to return,
Re: Data Loading into my Listbox does not look correct
Here is code I tested.
$listbox1.DataSource=$dataset.Tables[0]
$listbox1.DisplayMember='Name'
$listbox1.ValueMember='guid
The ValueMember can be any field in the table. That is what the listbox returns as the '$listbox1.SelectedValue'. This is what allows a listbox to be a lookup control. It can doisplay plain text names like a users full name and return the accountid or email address. In this case I have set it to return the GUID.
We can also easily leverage this to drive a filter for anotherlistbox.
$listbox1.DataSource=$dataset.Tables[0]
$listbox1.DisplayMember='Name'
$listbox1.ValueMember='guid
The ValueMember can be any field in the table. That is what the listbox returns as the '$listbox1.SelectedValue'. This is what allows a listbox to be a lookup control. It can doisplay plain text names like a users full name and return the accountid or email address. In this case I have set it to return the GUID.
We can also easily leverage this to drive a filter for anotherlistbox.
Re: Data Loading into my Listbox does not look correct
Thanks for the Help! Adding 'Name' to the send of my Load-Listbox command worked! However, when I tried to remove the Select at the end of the $dataset gather, this still did not work, because all I pulled back then is a bunch of rows that showed "System.Data.DataRow"jvierra wrote:Don't use select at teh end of teh where filter.
Call the listbox like this;
Load-ListBox $Listbox1 $names 'Name'
DO not enumerate in a for just hand the data set.
Listboxes are data capable so you can just assign the datatable as the data source and use the listbox data specs to assign the field to diaplay and teh field to return,
Re: Data Loading into my Listbox does not look correct
If I do a command to load the datasource into the Listbox - example...
$listbox1.datasource = $dataset.Tables[0]
How would I then filter out what I need from the $dataset to display into the Listbox?
$listbox1.datasource = $dataset.Tables[0]
How would I then filter out what I need from the $dataset to display into the Listbox?