Samples

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.
Locked
User avatar
timstspry11
Posts: 15
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Tue Jul 21, 2015 12:42 pm

Samples

Post by timstspry11 »

Hello, I am wondering if there are any sample scripts or walk-thru's for creating a simple GUI that would have a combo box populated with values from a SQL Server database along with some basic form validation/event handling like clicking on an item in the combo box would populate a list box with other values from the same SQL Server database.

Thanks in advance!

Tim

PowerShell Studio 2015
Build 4.2.93
64-bit product
Windows 8.1 OS

User avatar
SAPIEN Support Forums
Posts: 945
Joined: Wed Dec 03, 2014 2:26 pm

Samples

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, timstspry11.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***

jvierra
Posts: 14358
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Samples

Post by jvierra »

Here is the basic pattern:
PowerShell Code
Double-click the code block to select all.
$combobox1.DataSource=Get-MyDataTable 
   $combobox1.DisplayMember='username'
You can find many versions of functions that return a datatable object from a SQLServer database.

jvierra
Posts: 14358
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Samples

Post by jvierra »

Here is a simple datatable function.
PowerShell Code
Double-click the code block to select all.
function Get-DataTable{
	Param(
		$Instance="$env:COMPUTERNAME\SQLExpress",
		$Database='northWind',
		$Query='SELECT * FROM ORDERS'
	)
	
	$connString="Initial Catalog=$database;Data Source=$instance;;Integrated Security=SSPI;"
	$conn=New-Object System.Data.SqlClient.SqlConnection($connString)
	$conn.Open()
	$cmd=$conn.CreateCommand()
	$cmd.CommandText=$Query

	$adapter=New-Object System.Data.SqlClient.SqlDataAdapter($cmd)
	$datatable=New-Object System.Data.DataTable
	
	$rec=$adapter.Fill($datatable)
	Write-Host "Records returned=$rec"  -Fore green
	$conn.Close()
	$datatable
}

User avatar
timstspry11
Posts: 15
Joined: Tue Jul 21, 2015 12:42 pm

Re: Samples

Post by timstspry11 »

Thank you for your help! Are there any tutorials or books pertaining to how to use PowerShell Studio 2015? I am an experienced PowerShell script writer, but it is the PowerShell IDE I am having a hard time with.

Thanks in advance!

jvierra
Posts: 14358
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Samples

Post by jvierra »

The IDE is pretty much intuitive.

The HELP tab has links to the documentation. There are numerous blog articles about the tools.

https://www.sapien.com/blog/?s=powershell+studio

Locked