任何人都知道如何在c#中创建表达式任务以生成SSIS表达式任务吗?
谢谢。
我知道PrecedenceConstraint
。
请参阅我的代码:
Executable exe1 = pkg.Executables.Add("STOCK:SQLTask");
TaskHost TKHSQLHostMySQLTask = (TaskHost)exe1;
TKHSQLHostMySQLTask.Name = "my sql";
ExecuteSQLTask MySQLTask = (ExecuteSQLTask)TKHSQLHostMySQLTask.InnerObject;
//creating Execute SQL Task
MySQLTask.Connection = "sourcecon";
MySQLTask.SqlStatementSource = "select deptno from dbo.dept";
MySQLTask.SqlStatementSourceType = SqlStatementSourceType.DirectInput;
MySQLTask.BypassPrepare = false;
Executable exe2 = pkg.Executables.Add("STOCK:SQLTask");
TaskHost TKHSQLHostMySQLTask1 = (TaskHost)exe2;
ExecuteSQLTask MySQLTask1 = (ExecuteSQLTask)TKHSQLHostMySQLTask1.InnerObject;
//creating Execute SQL Task
MySQLTask1.Connection = "sourcecon";
MySQLTask1.SqlStatementSource = "select deptno from dbo.dept where deptname=?";
MySQLTask1.SqlStatementSourceType = SqlStatementSourceType.DirectInput;
MySQLTask1.BypassPrepare = false;
// Add input parameter binding
MySQLTask1.ParameterBindings.Add();
IDTSParameterBinding parameterBinding = MySQLTask1.ParameterBindings.GetBinding(0);
parameterBinding.DtsVariableName = "[User::Dname]";
parameterBinding.ParameterDirection = ParameterDirections.Input;
//parameterBinding.DataType = (int)OleDBDataTypes.VARCHAR;
parameterBinding.ParameterName = "0";
parameterBinding.ParameterSize = 255;
PrecedenceConstraint pc = pkg.PrecedenceConstraints.Add((Executable)exe1, (Executable)exe2);
pc.EvalOp = DTSPrecedenceEvalOp.ExpressionAndConstraint;
pc.Expression ="[User::myVar]>0";
//how to add Expression task ?
答案 0 :(得分:1)
SSIS 2012中的ExpressionTask
没有发布moniker。请改用ExpressionTask
可执行文件的CLSID。然后,您可以使用PrecedenceConstraint
将其连接到其他类。请参阅下面的示例。
确保在项目中引用Microsoft.SqlServer.ExpressionTask
程序集。
// Using the CLSID
Executable exExpressionTask =
pkg.Executables.Add("Microsoft.SqlServer.Dts.Tasks.ExpressionTask.ExpressionTask, Microsoft.SqlServer.ExpressionTask, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91");
TaskHost thExpressionTask = exExpressionTask as TaskHost;
ExpressionTask expressionTask = thExpressionTask.InnerObject as ExpressionTask;
// Set the expression.
expressionTask.Expression = @"10>0";
// Get the expression.
string expression = expressionTask.Expression;
// Validate the expression.
string str = expressionTask.ValidateExpression(null);