Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

How to fix Exception caused by space in text for Powershell form

11 December,2019 by Tom Collins

Question: I'm building a Powershell form GUI utilising the System.Windows.Forms  API.

I'm getting an error when passing text value  back to be processed from a text box defined by : 

$CommentsTxtBox = New-Object System.Windows.Forms.TextBox

 

Exception calling "ExecuteReader" with "0" argument(s): "Incorrect syntax near 'mytext'."

 

When I then take the space out of the Comments value – i.e change “New Value”   to    “NewValue”   I get the  New value generated message. So the space within the text value is generating the error 

 

How can I fix?

 

Answer: The quick answer is to place ' ' around the incoming value where you are processing the form values. For example : 

function myFormProcess 

{

$comments = $Comment

$SqlCmdqip = "Exec Generate_New '$comments' "

}

 

If you would like to know how to dig into Powershell read - Expand your Powershell mind – Three key cmdlets

 

 

 


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to fix Exception caused by space in text for Powershell form


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer