我正在将一个旧软件重写成一个 SSIS 包。我有一个类似于此的文本文件:
junk
other junk
other junk2
Sent: Friday, July 14, 2017 1:56 PM
more junk
more junk2
我需要打开文件(路径和文件名是常量),查找“Sent:” 并复制所有内容直到新行(在本例中为“Friday, July 14, 2017 1:56 PM") 到一个变量中,稍后可以由 SSIS 包使用。我的理解是 SSIS 没有所需的组件,我需要一个脚本任务来执行此操作。请问有人可以帮我解决这个问题吗?
此外,由于我没有使用脚本任务/C#/VB 的经验,因此非常感谢详细的指南。
最佳答案
您需要一个Script Component
而不是Script Task
因为您要在 中使用
级别。在您的 Flat File Connection
获取数据数据流Flat File Source
中只有一列并将其称为 Column0
。
然后添加一个Transformation
类型的Script Component
。首先转到 Input Columns
选项卡并选择 Column0
。然后,您需要返回到 Script
tap 并添加输出变量 OutputLine
,作为读写变量,如下所示:
点击Edit Script
按钮,有3种方法:PreExecute
、PostExecute
和Input0_ProcessInputRow
。将以下代码行添加到 PostExecute
和 Input0_ProcessInputRow
:
public override void PostExecute()
{
base.PostExecute();
this.Variables.OutputLine = LineValue;
}
// Add this variable that will hold the desired line value.
string LineValue = "";
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
if (Row.Column0.StartsWith("Sent:"))
{
LineValue = Row.Column0.Substring(5);
}
}
构建它,关闭它,点击OK
,你就完成了。
关于c# - 如何查看特定字符串的文本文件并将该字符串粘贴到 SSIS/C#/VB 中的变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45168805/