2012-07-26 64 views
0

我需要解析我的ssis包中的所有用戶變量。到目前爲止,我能夠獲取包中所有變量的名稱和值。我需要獲取名稱和值並將它們轉儲到表中。到目前爲止,我可以通過消息框顯示名稱和值,但我似乎無法弄清楚,腳本任務如何將這些值轉儲到表中。任何幫助將不勝感激。SSIS腳本任務獲取所有變量名稱和值

using System; 
using System.Data; 
using Microsoft.SqlServer.Dts.Runtime; 
using System.Windows.Forms; 
//using System; 
////using Microsoft.SqlServer.Dts.Runtime; 
namespace ST_81ec2398155247148a7dad513f3be99d.csproj 
{ 
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")] 
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase 
    { 

     #region VSTA generated code 
     enum ScriptResults 
     { 
      Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, 
      Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure 
     }; 
     #endregion 

    public void Main() 
    { 


     Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application(); 
     // Load a sample package that contains a variable that sets the file name. 
     Package pkg = app.LoadPackage(
      @"C:\PackagePath\" + 
      @"Template0719.dtsx", 
      null); 
     Variables pkgVars = pkg.Variables; 
     foreach (Variable pkgVar in pkgVars) 
     { 

      MessageBox.Show(pkgVar.Name); 
      MessageBox.Show(pkgVar.Value.ToString()); 
     } 
     Console.Read(); 
    } 
    } 

    } 
+0

[輸出變量名稱和SSIS包中的值]的可能重複(http://stackoverflow.com/questions/11678365/output-variable-name-and-value-in-ssis-package) – 2012-07-27 19:09:48

回答

0

既然您知道如何獲取變量列表,您可以創建一個數據源腳本組件。

相關問題