How can I access variables inside my C# code which I've used in Data Flow -> Script Component - > My c# Script with my SSIS package?

我试过了,也不管用

IDTSVariables100 varCollection = null;
this.VariableDispenser.LockForRead("User::FilePath");
string XlsFile;

XlsFile = varCollection["User::FilePath"].Value.ToString();

推荐答案

访问(数据流任务的)脚本Component中的包变量与访问脚本Task中的包变量不同.对于脚本组件,首先需要打开Script Transformation Editor(右键单击组件并 Select "编辑…").在"脚本"选项卡的"自定义属性"部分中,可以输入(或 Select )要使脚本可用的属性(只读或读写):

// Modify as necessary
public override void PreExecute()
{
    base.PreExecute();
    string thePath = Variables.FilePath;
    // Do something ...
}

public override void PostExecute()
{
    base.PostExecute();
    string theNewValue = "";
    // Do something to figure out the new value...
    Variables.FilePath = theNewValue;
}

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    string thePath = Variables.FilePath;
    // Do whatever needs doing here ...
}

一个重要的警告:如果需要将包变量设置为write,则只能在PostExecute()方法中执行此操作.

关于代码片段:

IDTSVariables100 varCollection = null;
this.VariableDispenser.LockForRead("User::FilePath");
string XlsFile;

XlsFile = varCollection["User::FilePath"].Value.ToString();

varCollection初始化为null,并且从未设置为有效值.因此,try 取消引用它将失败.

Database相关问答推荐

重新运行后未找到 Taipy 场景

有关托管默认 SQL Server 实例的 Azure VM 数据库服务器的问题

怎么修复ORA-28001: the password has expired

一个强大的 MySQL 管理工具,具有与 SQL Server Management Studio 类似的功能

有使用 H2 数据库的实际经验吗?

Android SQLiteno such table异常

如何开始使用 SQLCipher for android?

PostgreSQL - 按时间戳值分组?

授予对具有特定前缀的多个表的权限

Spring Framework 中的默认隔离级别

SQL 历史(history)表设计

我可以在 mysql 中的 select 语句上启动触发器吗?

Oracle在哪些情况下会自动创建索引?

South migration error: NoMigrations exception for django.contrib.auth

每个 Docker 容器一个或多个数据库

触发器、断言和判断之间有什么区别?

如何在一行中显示 redis 中的所有键?

为数据库应用程序留下审计跟踪/更改历史的有效策略?

在 MySQL 存储过程中使用if和else

什么是非关系数据库的例子?