Script Task Code Help Needed

  • Try this.

    Set Option Strict Off [/b]at the top of Script Task

    If Dts.Variables("JobSiteCode").Value <> "" Then [NOT NULL]

    Dts.Variables("sJobSiteCode").Value = Dts.Variables("JobSiteCode")Else

    Dts.Variables("sJobSiteCode").Value = ""

    End If

    NOT NULL -was my comment.

    I was basically trying to say if the value is not equal to empty / is not null.Which means it has a value and is not null

    Sorry for the misleading info

  • Thanks for your reply. I don't understand your syntax of "Then [Not Null]", and either does the compiler. If I remove that, then the code doesn't address Null results. I have to admit that I'm coming from a VB6 environment and do not know VB .Net, so if your method of addressing Nulls is sound but your syntax was written wrong, please let me know.

    Thanks

  • Try this:

    If Dts.Variables("JobSiteCode") Is Nothing Then

    Dts.Variables("sJobSiteCode").Value = ""

    Else

    Dts.Variables("sJobSiteCode").Value = Dts.Variables("JobSiteCode")

    End If

    You can also use the following:

    If IsNothing(Dts.Variables("JobSiteCode")) Then

    Dts.Variables("sJobSiteCode").Value = ""

    Else

    Dts.Variables("sJobSiteCode").Value = Dts.Variables("JobSiteCode")

    End If

  • Thanks. I can't say if it will work or not b/c I've been pulled onto another project and I have to put this aside for awhile. I do know that the syntax was accepted by the compiler. However I'm concerned that Is Nothing is not the same as testing for Is Null b/c my understanding is that they are not the same values (from what i understand, nothing is not a value but null is).

  • Not sure what you mean by "Null". Where is the value coming from? From a database call? If so, you may need to compare against DBNull.Value.

  • The value is coming from a database call issued in an ExecuteSQL task and passed through to a ForEach Loop Container for use by the Script. Variables have been created to hold the data. The database field is a nullable field. So I would like to test for a Null value and pass a blank to the next step, Insert, instead of a Null value.

    You're probably correct regarding the use of DBnull, since my research indicates that VB .Net uses DBnull rather than Null. Unfortunately, being a VB6 programmer my .Net expertise is limited.

Viewing 6 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply