title: Increment a variable within a Foreach Loop and use it-SSIS
body: <p>I have a package i am using the foreach loop to loop through the databases. I am passing a string and it loops though all the databases. Everything is perfect till here.</p>
  
  <p>What i want to achieve is that for each databases it loops, it should increment a variable by 1. suppose if i have to loop through a total of 5 databases. And a package level variable(myvariable =24) is declared as 24. for each databases it loops it should increment the variable by 1.</p>
  
  <p>For that i have created a script task inside the foreachloop container. ReadWriteVariables as myvariable. In the script editor. I have the following code</p>
  
  <pre><code>public void Main()
          {
       int varbl = Convert.ToInt32(Dts.Variables["User::myvariable"].Value.ToString());
       varbl++
         }
  </code></pre>
  
  <p>and then i am passing that incremented value to a storedprocedure. But its not incrementing. It is still taking the default value of 24. Any ideas how can i increment a variable in foreachloop container?</p>