Page 1 of 1

Samples

Posted: Fri Aug 28, 2015 8:03 am
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

Samples

Posted: Fri Aug 28, 2015 8:03 am
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 ***

Re: Samples

Posted: Fri Aug 28, 2015 8:36 am
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.

Re: Samples

Posted: Fri Aug 28, 2015 8:41 am
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
}

Re: Samples

Posted: Fri Aug 28, 2015 8:48 am
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!

Re: Samples

Posted: Fri Aug 28, 2015 9:09 am
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