有没有办法在SSIS组件脚本中使用ProcessInputRow函数中的本地/全局变量来保持数字的运行计数?
例如:
Row1: 1
Row2: 1
Row3: 0
所以说变量设置为default = 0
在第1行之后,变量现在将是= 1
在第2行之后,变量现在将是= 2
在第3行之后,变量现在将是= 1
由于ProcessInputRow函数单独处理每个输入行,它会重置我的局部变量,并且你不能在PostExecute()之外使用SSIS用户创建的变量,我在这里不知所措。
答案 0 :(得分:1)
private int count = 0;
public override void PreExecute()
{
base.PreExecute();
//some code where you can increment count
}
public override void PostExecute()
{
base.PostExecute();
// Count it accessible here as well
}
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
//Count will be accessible but not reset here
}
如果这回答了您的问题,请告诉我
答案 1 :(得分:1)
实际上非常简单 - 在脚本组件的ScriptMain
类中使用成员变量(也称为field):
/* Microsoft SQL Server Integration Services Script Component
* Write scripts using Microsoft Visual C# 2008.
* ScriptMain is the entry point class of the script.*/
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
private int _myVariable = 0;
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
Row.SomeValue = _myVariable;
_myVariable = Row.SomeOtherValue;
}
}