如何访问我的C#代码中的变量,我已经在数据流->脚本组件->我的c#脚本与我的SSIS包?
我试过了,它也不起作用
IDTSVariables100 varCollection = null;
this.VariableDispenser.LockForRead("User::FilePath");
string XlsFile;
XlsFile = varCollection["User::FilePath"].Value.ToString();
发布于 2018-02-21 19:23:59
首先,在脚本任务编辑器中列出要在ReadOnlyVariables的脚本任务中使用的变量,然后编辑脚本
在脚本代码中使用ReadOnlyVariables
String codeVariable = Dts.Variables["User::VariableNameinSSIS"].Value.ToString();
这行代码将把ssis包变量视为字符串。
发布于 2018-02-21 06:43:03
我遇到了与OP相同的问题,只是我记得声明了ReadOnlyVariables。
在尝试了一段时间后,我发现问题出在变量的名称上。SSIS中的"File_Path“不知何故被转换成了"FilePath”。C#不能很好地处理变量名中的下划线。
因此,要访问该变量,我输入
string fp = Variables.FilePath;
在脚本组件的PreExecute()方法中。
发布于 2013-12-04 22:52:13
强类型的var似乎不可用,我必须执行以下操作才能访问它们:
String MyVar = Dts.Variables["MyVarName"].Value.ToString();
https://stackoverflow.com/questions/13450289
复制相似问题