在Foreach循环中增加一个变量并使用它 - SSIS [英] Increment a variable within a Foreach Loop and use it-SSIS
问题描述
我有一个包,我正在使用foreach循环来遍历数据库。我传递一个字符串,它循环所有的数据库。一切都是完美的,直到这里。
我想要实现的是,对于每个数据库它循环,它应该增加一个变量1.假设如果我必须通过循环共有5个数据库。而一个包级变量(myvariable = 24)被声明为24.对于每个数据库,它循环它应该增加1变量。
为此我创建了一个脚本foreachloop容器内的任务。 ReadWriteVariables作为myvariable。在脚本编辑器中。我有以下的代码:
pre $ $ $ $ $ $ $
$ varbl = Convert.ToInt32( Dts.Variables [ 用户:: MYVARIABLE] Value.ToString())。
varbl ++
}
然后我将该增量值传递给存储过程。但它不增加。它仍然采取默认值24。任何想法如何增加一个变量在foreachloop容器?
变量 varbl
你创建的只存在于脚本上下文中。
为了增加SSIS变量,你需要像
public void Main()
{
int varbl = Convert.ToInt32(Dts.Variables [User :: MYVARIABLE] Value.ToString())。
varbl ++;
Dts.Variables [User :: myvariable]。Value = varbl;
$ / code>
或变量 User :: myvariable
不会改变
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.
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.
For that i have created a script task inside the foreachloop container. ReadWriteVariables as myvariable. In the script editor. I have the following code
public void Main()
{
int varbl = Convert.ToInt32(Dts.Variables["User::myvariable"].Value.ToString());
varbl++
}
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?
The variable varbl
that you created only exists in the script context.
To increment the SSIS variable you need to do something like
public void Main()
{
int varbl = Convert.ToInt32(Dts.Variables["User::myvariable"].Value.ToString());
varbl++;
Dts.Variables["User::myvariable"].Value = varbl;
}
or the variable User::myvariable
will not be changed
这篇关于在Foreach循环中增加一个变量并使用它 - SSIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!