0

我正在尝试输出所有用户变量的名称及其值,然后将这些值存储在表中。我设法解析变量及其值,但现在它给了我所有变量(系统和用户)。另外,我似乎无法弄清楚如何将值分配给表。任何帮助将不胜感激..以下是我到目前为止的想法。

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();
    }
    }

    }
4

1 回答 1

1

这对我有用

我创建了一个包含每种类型变量的包,因此以 SSIS 数据类型命名, 每个数据类型的变量

使用您的应用程序和 pkg 声明/实例,我使用了以下内容

        boolean interactiveMode = true;
        foreach (Variable item in pkg.Variables)
        {
            try
            {
                if (!item.Namespace.Equals("System"))
                {
                    // item.Value.ToString()
                    string value = (item.Value == null) ? string.Empty : item.Value.ToString();
                    string name = item.Name;
                    string scope = item.Namespace;
                    string type = item.DataType.ToString();
                    string output = string.Format("Name {0, -20} | Scope {1, -10} | Data Type {2, -10} | Value {3, -20}", name, scope, type, value);
                    if (interactiveMode)
                    {
                        MessageBox.Show(output);
                    }
                    else
                    {
                        bool fireAgain = true;
                        Dts.Events.FireInformation(0, "Variable enumeration", output, string.Empty, 0, ref fireAgain);
                    }

                }

            }
            catch (Exception ex)
            {

                Dts.Events.FireError(0, "enumerate", ex.ToString(), string.Empty, 0);
            }
        }

产生预期值

---------------------------

---------------------------
Name VariableDbNull       | Scope User       | Data Type Empty      | Value                     
---------------------------
OK   
---------------------------

---------------------------

---------------------------
Name VariableDouble       | Scope User       | Data Type Double     | Value 0                   
---------------------------
OK   
---------------------------
于 2012-07-27T19:06:32.470 回答