So far I have created a form in Powershell studio and from that form I want to take the user's input and place it into a SQL Server database.
For the most part this works fine, unless a textfield in the form is left blank, then an error occurs. I need to be able to insert the data even if some of the fields are not complete as people are able to go back and edit and add to that data and then update it in the database.
This is the error I get if I leave a textbox blank:
ERROR: Exception calling "Fill" with "1" argument(s): "Incorrect syntax near ','." testTabForm.psf (59): ERROR: At Line: 59 char: 3
ERROR: + $SqlAdapter.Fill($DataSet)
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
ERROR: + FullyQualifiedErrorId : SqlException
And the code which does this aspect of it is the following:
$server = "server"
$database = "database"
$A = $record.Text
$B = $textB.Text
$C = $textC.Text
$insert = "INSERT INTO dbo.AMY (ColumnA, ColumnB, ColumnC) VALUES ($A,$B,$C)"
$connectionTemplate = "Data Source=$server;Integrated Security=SSPI;Initial Catalog=$database;"
$connectionString = [string]::Format($connectionTemplate, $server, $database)
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$command = New-Object System.Data.SqlClient.SqlCommand
$command.CommandText = $insert
$command.Connection = $connection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $command
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$connection.Close()
Any ideas on how to fix this would be appreciated.