August 6, 2010 at 7:17 am
Hi, I've got a package that reads CSDVersion and Caption from the win32_operatingsystem using a WMI Reader Task and puts that into an object. I then use a ForEach container to put those values into string variables. Works great until I come across a server with no Service Pack and the CSDVersion value is NULL. I then get an error on the FOREACH container - THE TYPE OF VALUE BEING ASSIGNED TO VARIABLE ... DIFFERS FROM THE CURRENT VARIABLE TYPE.
Any Idea how to get around this? This is the WMI Query that I'm using
Select Caption, CSDVersion from win32_operatingSystem
I didn't see any WQL function like ISNULL.
Thanks
August 6, 2010 at 8:01 am
I don't know WQL, so therefore have no idea whether this will work, but can you force a non-null result by using something like:
Select Caption, '' + CSDVersion from win32_operatingSystem
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
August 6, 2010 at 10:30 am
Other option is to declare the variable as type "Object".
Then you have convert it back to string and store that in a string variable in an activex script like below..
Dts.Variables("test1").Value = Convert.ToString(Dts.Variables("Variable").Value).ToString()
Here "test1" is of string type and "variable" is of object type which has the null value.
[font="Arial"]BASKAR BV
http://geekswithblogs.net/baskibv/Default.aspx
In life, as in football, you won’t go far unless you know where the goalposts are.[/font]
August 6, 2010 at 11:37 am
Thanks, That worked as a workaround.
August 10, 2010 at 4:54 am
Baskar B.V (8/6/2010)
Other option is to declare the variable as type "Object".Then you have convert it back to string and store that in a string variable in an activex script like below..
Dts.Variables("test1").Value = Convert.ToString(Dts.Variables("Variable").Value).ToString()
Here "test1" is of string type and "variable" is of object type which has the null value.
Which is very obvious as .value has a return type of String hence casting.
Here you may avoid Convert.ToString() as .ToString() is appended to take care of the conversion.
Moreover, it is also advisible to avoid such boxing/unboxing....it is considered as a bad practice...just to suit one's need.
Raunak J
August 10, 2010 at 9:31 am
Which is very obvious as .value has a return type of String hence casting.
Here you may avoid Convert.ToString() as .ToString() is appended to take care of the conversion.
We can't avoid Convert.ToString() since the variable "Variable" is of type object. If we do as you say we get the value as "System.Object" instead of the actual string value.
Moreover, it is also advisible to avoid such boxing/unboxing....it is considered as a bad practice...just to suit one's need.
Convert is required to convert the object variable to string data type and tostring() is to get the value inside the variable. Instead of padding empty character in sql code, i feel it is better to do it in the active scripting. It is debatable to decide which one is best practice (padding empty characters or doing it in activex scripting)???
[font="Arial"]BASKAR BV
http://geekswithblogs.net/baskibv/Default.aspx
In life, as in football, you won’t go far unless you know where the goalposts are.[/font]
August 11, 2010 at 4:37 am
Baskar B.V (8/10/2010)
Which is very obvious as .value has a return type of String hence casting.
Here you may avoid Convert.ToString() as .ToString() is appended to take care of the conversion.
We can't avoid Convert.ToString() since the variable "Variable" is of type object. If we do as you say we get the value as "System.Object" instead of the actual string value.
Moreover, it is also advisible to avoid such boxing/unboxing....it is considered as a bad practice...just to suit one's need.
Convert is required to convert the object variable to string data type and tostring() is to get the value inside the variable. Instead of padding empty character in sql code, i feel it is better to do it in the active scripting. It is debatable to decide which one is best practice (padding empty characters or doing it in activex scripting)???
Fortunately, Baskar, we can avoid the initial code "Convert.ToString"....as it is redundant
static void Main(string[] args)
{
float o=123; 'Step 1
string s = o.ToString(); 'Step 2
}
From Step 1, we get o=123.0
From Step 2, we get s="123"
Raunak J
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply