我得到我的PowerShell腳本的錯誤是:SQL的ExecuteNonQuery錯誤PowerShell中查詢與布爾
Exception calling "ExecuteNonQuery" with "0" argument(s): "Invalid column name 'False'.
function InsertData {
Param (
[string]$username,
[string]$fullname,
[string]$email,
[string]$phone
)
$DBServer = "SERVERNAME"
$DBName = "Tool"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Server=$DBServer;Database=$DBName;Integrated Security=False;User Id = User;password = password"
$sql = "INSERT INTO Employee (LocationId,FullName,username,email,phone,EquipId,SystemDetailId,migrationdate,UAT,bdpaccess) VALUES ('" + $location + "','" + $fullname + "','" + $username + "','" + $email + "','" + $phone + "',5,4," + $migrationdate + ",False,False)"
$sqlCommand = New-Object System.Data.SqlClient.SqlCommand
$sqlCommand.Connection = $sqlConnection
$sqlCommand.CommandText = $sql
write-host $sql
$sqlConnection.Open()
$sqlCommand.ExecuteNonQuery()
$sqlConnection.Close()
}
我顯然是做錯了什麼地方我打字「假,假「作爲聲明的一部分。我嘗試了所有大寫,小寫,0和1,沒有任何作用。當我使用Write-Host $ sql將它寫入powershell命令窗口時,它看起來很好。
如果SQL數據類型是位,則爲文字指定零。考慮一個參數化查詢。 –
這是怎麼回事?它看起來像一個SQL注入噩夢對我來說。甚至像一個有全名撇號的人的良性數據(「O'brien」,Bobby Tables)也會殺死這個死人。 –
我試過參數,但他們沒有工作,他們得到了太多的錯誤。 –