查找 SSIS 脚本组件中的最后一行
我有一个 SSIS 2008 脚本组件,它使用以下方法
Input0_ProcessInputRow(Input0Buffer 行)
来处理行。有没有办法确定我正在读取的行是否是数据集中的最后一行。
I have an SSIS 2008 script component and it uses the method
Input0_ProcessInputRow(Input0Buffer
Row)
to process the Rows. Is there a way to find if the Row I'm reading is the Last Row in the Dataset.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
重写 InputRows_ProcessInput 的解决方案对我有用。但是,不要随意使用该代码。方法的名称取决于您的输入的名称。在我的例子中,方法签名是:
找出正确方法的一个简单方法是进入脚本并输入“base.Input”intellisense 应该为您提供正确的重写方法。
仅仅检查“Buffer.EndOfRowset()”是不够的,并且它在“while (Buffer.NextRow())”循环中不起作用。所以我猜“EndOfRowset”发生在最后一行之后。
The solution of overriding InputRows_ProcessInput worked for me. However, don't use the code litterally. The name of the method depends on the name of your Input. In my case the method signature was:
An easy way to find out the correct method is to go in the script and type "base.Input" intellisense should provide you the correct method to override.
Simply checking for "Buffer.EndOfRowset()" is not sufficient and it doesn't work inside the "while (Buffer.NextRow())" loop. So I guess the "EndOfRowset" occurs after the last row.
我以前没有尝试过,但在您的脚本组件之前,添加一个 RowCount 任务并在此任务中设置一个变量的值(称为 RowCnt,此处初始化为 0)。然后在您的脚本中,有类似这样的内容(确保变量声明的范围在类中)...
这应该允许您处理最后一行。
I've not tried this before, but before your Script Component, add a RowCount Task and set the value of a variable (called RowCnt, initialised to 0 here) in this task. Then in your script, have something like this (ensure the variable declaration is scoped in the Class)...
That should allow you to process the final row.
重写 InputRows_ProcessInput 方法,如下所示:
Override the InputRows_ProcessInput method as follows:
自定义脚本代码写在 ScriptMain 类中。该类继承自 UserComponent,其中包含一个虚拟方法 FinishOutputs()。您可以在 ScriptMain 中覆盖它以执行最后一行之后需要运行的代码。
UserComponent 中的相关代码。
请注意,此代码是自动生成的,无法更改。然而,它确实有效地为您提供了放置代码的位置,因为您可以在 ScriptMain 中的代码中重写 FinishOutputs(),如下所示:
The custom script code is written inside the ScriptMain class. This class inherits from UserComponent which contains a virtual method FinishOutputs(). You can override this in ScriptMain to execute the code you need to run after the last row.
Relevant code in UserComponent.
Notice that this code is auto-generated and cannot be changed. It does however effectively give you place to put your code as you can override FinishOutputs() in your code within ScriptMain like this: