Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.Net/SSIS脚本任务-处理空值_Vb.net_Ssis - Fatal编程技术网

Vb.Net/SSIS脚本任务-处理空值

Vb.Net/SSIS脚本任务-处理空值,vb.net,ssis,Vb.net,Ssis,请参阅下面的代码(处理空值的问题) Framework.GetValue-返回STRING(获取存储在数据库中的值) 问题-当Framework.GetValue因为数据库中不存在值而不返回任何内容时,它会在SSIS脚本组件中抛出错误。如何捕获NULL是我们面临的问题 公共函数GetValue(ByVal FetchParameter作为字符串)作为字符串 Dim lGetValue As String = String.Empty Using Conn New SqlConnection(C

请参阅下面的代码(处理空值的问题)

Framework.GetValue
-返回
STRING
(获取存储在数据库中的值)

问题-当Framework.GetValue因为数据库中不存在值而不返回任何内容时,它会在SSIS脚本组件中抛出错误。如何捕获
NULL
是我们面临的问题

公共函数GetValue(ByVal FetchParameter作为字符串)作为字符串

Dim lGetValue As String = String.Empty

Using Conn New SqlConnection(ConnString)
    SQLCommand = New SqlCommand("ParameterValues", _ETLFrameworkConn)
    SQLCommand.CommandText = "Select ParamValue from ParameterValues where Parameter_Name=@ParameterField"
    SQLCommand.Parameters.Add(New SqlParameter("@ParameterField").Value SqlDbType.NVarChar))
    SQLCommand.Parameters("@ParameterField").Value = FetchParameter 
    Try
        Conn.Open()
        lGetValue = SQLCommand.ExecuteScalar()
    Catch ex As Exception

    End Try
End Using

Return lGetValue 
端函数


请在GetValue()函数中尝试以下代码段。在代码中添加了DBNULL处理。如果没有值字符串,则将写入空

Dim lGetValue As String = String.Empty

Using Conn New SqlConnection(ConnString)
    SQLCommand = New SqlCommand("ParameterValues", _ETLFrameworkConn)
    SQLCommand.CommandText = "Select ParamValue from ParameterValues where Parameter_Name=@ParameterField"
    SQLCommand.Parameters.Add(New SqlParameter("@ParameterField").Value SqlDbType.NVarChar))
    SQLCommand.Parameters("@ParameterField").Value = FetchParameter 
    Try
        Conn.Open()
        var retrunVal = (string)SQLCommand.ExecuteScalar()

        IF returnVal = DBNULL.Value Then
            lGetValue = returnVal
        End

    Catch ex As Exception

    End Try
End Using

Return lGetValue 

希望这有帮助

您遇到了什么错误?能否在方法GetValue()中发布代码?我想您需要在返回之前检查DBNULL.value的值。我已经添加了代码,请您看一下。ReturnVal的类型是什么?您还可以建议,当从这个函数传递的值在SSIS中分配给INTEGER类型时,它会给我错误。我如何进行强制转换?从代码中我了解到该方法返回字符串。SSIS将抛出错误。您应该知道数据类型。GetValue()方法的数据类型是什么?returnVal的类型是什么?ExecuteScalar()returns将返回对象。修改代码以将值类型转换为字符串。
Dim lGetValue As String = String.Empty

Using Conn New SqlConnection(ConnString)
    SQLCommand = New SqlCommand("ParameterValues", _ETLFrameworkConn)
    SQLCommand.CommandText = "Select ParamValue from ParameterValues where Parameter_Name=@ParameterField"
    SQLCommand.Parameters.Add(New SqlParameter("@ParameterField").Value SqlDbType.NVarChar))
    SQLCommand.Parameters("@ParameterField").Value = FetchParameter 
    Try
        Conn.Open()
        var retrunVal = (string)SQLCommand.ExecuteScalar()

        IF returnVal = DBNULL.Value Then
            lGetValue = returnVal
        End

    Catch ex As Exception

    End Try
End Using

Return lGetValue