title: SSIS Null handling, script task
body: <p>I am having trouble with MS SSIS. I would like to download and upload stuff to database. I am looking for the best practice, or why i get an error.</p>
  
  <p>I use the control flow (other tasks are called). There are nulls in a column in the data I download. For this I can't use string or integer, or else it exits with error (execute sql task). So I use object. Example: Variable sBorderName is object, the data from a column goes here. </p>
  
  <p>I would like to upload this to an other database table. There can also be null in that colum for example. I cannot upload the object variable, because I get database type missmatch. </p>
  
  <p>When I try to eliminate the null-s with a script task (C#), I use the following:
  sBorderName is object
  sBorderNameSafe is string</p>
  
  <pre><code>if (Dts.Variables["User::sBorderName"].Value == null)
  {
      Dts.Variables["User::sBorderNameSafe"].Value = "NULL ERROR";
  }
  else
  {
      Dts.Variables["User::sBorderNameSafe"].Value = 
          (String)Dts.Variables["User::sBorderName"].Value;
  }
  </code></pre>
  
  <p>I get runtime error, with no hint on what is wrong. The error originates from the else case. I have double checked the variables, scope, write/read permissions etc. </p>
  
  <p>Can you please help me? What is wrong with this? What is the way to solve the problem if you have a better idea?</p>
  
  <p>Sziro</p>
  
  <p>UPDATE:</p>
  
  <pre><code>Dts.Events.FireWarning(14, "Display Script", "sBorderName is:" + Dts.Variables["User::sBorderName"].Value, "", 0); 
  </code></pre>
  
  <p>does work, it shows "sBorderName is: "</p>
  
  <p>However every casting of the value exits with runtime error</p>
  
  <pre><code>(String)Dts.Variables["User::sBorderName"].Value
  </code></pre>
  
  <p>How can one handle this correctly?</p>