在 Foreach 循环中递增变量并使用它-SSIS
我有一个包,我正在使用 foreach 循环来循环数据库。我正在传递一个字符串,它会循环遍历所有数据库。到这里一切都很完美。
我想要实现的是,对于它循环的每个数据库,它应该将变量增加 1。假设我必须循环遍历总共 5 个数据库。包级变量(myvariable =24)被声明为 24。对于它循环的每个数据库,它应该将变量增加 1。
为此,我在 foreachloop 容器内创建了一个脚本任务。 ReadWriteVariables 作为 myvariable。在脚本编辑器中。我有以下代码
public void Main()
{
int varbl = Convert.ToInt32(Dts.Variables["User::myvariable"].Value.ToString());
varbl++
}
,然后将该增量值传递给存储过程。但它并没有增加。它仍然采用默认值 24。有什么想法可以增加 foreachloop 容器中的变量吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您创建的变量
varbl
仅存在于脚本上下文中。要增加 SSIS 变量,您需要执行类似的操作
,否则变量
User::myvariable
将不会更改The variable
varbl
that you created only exists in the script context.To increment the SSIS variable you need to do something like
or the variable
User::myvariable
will not be changed