SqlClient.ExecuteNonQuery not returning number of rows SqlClient.ExecuteNonQuery not returning number of rows powershell powershell

SqlClient.ExecuteNonQuery not returning number of rows


You're trying to invoke a method without parentheses. When doing that, instead of actually invoking the method the statement will display a list of the overloads (see for instance here), which cannot be cast to an integer, even if you convert it to a string first.

Change

[int]($SQLCommand.ExecuteNonQuery | Out-String)

into

[int]$SQLCommand.ExecuteNonQuery()

and the code should do what you want.