我正在传递一个用于 Oracle 插入的参数哈希表。哈希表 Value 的内容是一个数组。我不断收到此错误:
Exception setting "Value": "Value does not fall within the expected range."
当我尝试使用数组绑定添加值时。我有一个有效的命令对象,并将 ArrayBindCount 设置为正确的值。这是我正在使用的代码和输出。这应该工作!请注意,$parameterValues 变量包含我传入的哈希表:
$cmdObject = New-Object Oracle.DataAccess.Client.OracleCommand($sqlStatement,$connectionObject)
$cmdObject.BindByName = $true
if($parameterValues)
{
ForEach($p in $parameterValues.GetEnumerator())
{
$cmdObject.ArrayBindCount = $p.Value.Count
Write-Host ("ParameterName = ""{0}"" type = {1} Parameter Value Type = {2} Count = {3}" -f $p.Key, $p.Key.GetType().FullName, $p.Value.GetType().FullName, $p.Value.Count)
$oraParam = New-Object Oracle.DataAccess.Client.OracleParameter
$oraParam.ParameterName = $p.Key
$oraParam.Value = $p.Value
$cmdObject.Parameters.Add($oraParam) | Out-Null
}
Write-Host("Number of parameters in `$cmdObject.Parameters = {0}" -f $cmdObject.Parameters.Count)
Write-Host ("Value of `$cmdObject.ArrayBindCount = {0}" -f $cmdObject.ArrayBindCount)
这是我得到的输出和错误:
Value of $cmdObject.CommandText = insert into regions (region_id, region_name) values (:REGION_ID, :REGION_NAME)
ParameterName = "REGION_NAME" type = System.String Parameter Value Type = System.String[] Count = 4
Exception setting "Value": "Value does not fall within the expected range."
At C:\Users\areum\Downloads\wd\Scratch\HelloPSWorld_functions.ps1:1615 char:4
+ $oraParam.Value = $p.Value
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
ParameterName = "REGION_ID" type = System.String Parameter Value Type = System.Int32[] Count = 4
Exception setting "Value": "Value does not fall within the expected range."
At C:\Users\areum\Downloads\wd\Scratch\HelloPSWorld_functions.ps1:1615 char:4
+ $oraParam.Value = $p.Value
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
Number of parameters in $cmdObject.Parameters = 2
Value of $cmdObject.ArrayBindCount = 4
我就是不能让它工作!请帮忙!