Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Manipulating SSIS variables in script task


Manipulating SSIS variables in script task

Author
Message
jo_square
jo_square
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 8
I have a SSIS package with a script task which I would like to calculate the sum of two int32 variables(say "a" and "b", package level var) and store in variable "c". I'm not familiar with VB/.NET and I follow some books' example and wrote the following code:
-------
If ((Dts.Variables.Contains("a") = True) And (Dts.Variables.Contains("b") = True)) Then

Dts.Variables("c").Value = Dts.Variables("a").Value + Dts.Variables("b").Value

End If
-------
The IDE told me that "Option Strict On prohibits operands of type Object for operator '+'". I don't know also how to set the property of a variable to be readable/writable. Could someone tell me what should I amend to make the script work? Thank you!
Todd Engen
Todd Engen
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1081 Visits: 6336
The variables would added to the ReadWriteVariables option which is on the same tab where you clicked on Design Script... of the Script Task.
jo_square
jo_square
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 8
Thanks. I think I've already added those variables to the properties (using the format of "User::a", "User::b", etc, w/o quote), is it right? However, it still shows that error message. Would you mind to teach me the necessary steps to make it work? Or point out the steps that maybe missing? Thank you!
Todd Engen
Todd Engen
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1081 Visits: 6336
First, the variables would be specified as "a,b,c" (without the quotes).

Second, "Option Strict" is a compiler option that's there to help you from introducing logic errors.

For example, set the type for variable "a" to Boolean and set it to true. Set the type for variable "b" to Int32 and set it to 3. Open the script and add "Option Strict Off" at the top and then run the task. With checking off it will not only run but give you an incorrect result.

To make this work, explicitly convert the variables before adding them.

CInt(DTS.Variables("a").value) + CInt(DTS.Variables("b").value)
jo_square
jo_square
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 8
Got it! Thank you! BigGrin
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search