2016-12-24 4 views
0

SSIS SQLタスクにパラメータマッピングを追加する方法を検討しています。C#でSSISパッケージにパラメータバインディングを追加する

so far I am able to create my SQL Task, and set a few properties. 
TaskHost taskhost = sequence1.Executables.Add("STOCK:SQLTask") as TaskHost; 
        taskhost.Name = myTable.ToString(); 
        taskhost.Properties["Connection"].SetValue(taskhost, connMgrOleDb.Name); 
        taskhost.Properties["SqlStatementSource"].SetValue(taskhost, "EXEC sp_GET_S_" + myTable.ToString() +"?, ?"); 


// need to add input parameter binding 

//任意のアイデア??

答えて

0

TaskHostオブジェクトを使用してプロパティを設定していることがわかります。プロパティを動的に設定する場合は、TaskHostを使用することをお勧めします。基本的な制御フロータスクを直接使用してプロパティを設定することもできますが、場合によってはそれが望ましい場合もあります。

ここでExecuteSQLTaskオブジェクトを直接使用してパラメータバインディングを追加できます。 ExecuteSqlTask​​のParameterBindingsプロパティでAddメソッドを呼び出すだけです。

ExecuteSqlTask​​オブジェクトを使用するには、Microsoft.SqlServer.SQLTask.dllにアセンブリ参照を追加する必要があります。

TaskHostのInnerObjectをExecuteSqlTask​​にキャストし、ExecuteSqlTask​​のParameterBindingsプロパティでAddメソッドを呼び出します。結果バインディングも追加するために同じパターンが使用されます。

 // cast the TaskHost's InnerObject as ExecuteSqlTask 
     // add a reference to the Microsoft.SqlServer.SQLTask.dll to use ExecuteSqlTask 
     ExecuteSQLTask sqlTask = TaskHost.InnerObject as ExecuteSQLTask; 

     // call the Add method on ParameterBindings property of sqlTask. 
     //This will return a IDTSParameterBinding object 
     IDTSParameterBinding parameterBinding = sqlTask.ParameterBindings.Add(); 

     // using the IDTSParameterBinding object that is returned from the Add call, set the various properties 
     parameterBinding.ParameterName = "ParamName"; 
     parameterBinding.ParameterDirection = ParameterDirections.Input; 
     // set more properties on parameterBinding as needed ...... 
+0

ありがとうございました – Tempest

関連する問題