将DataFlow脚本组件中的RecordSet枚举为数据源

Rhy*_*ysW 5 c# ssis

这是与SSIS相关的问题

我有一个设置为对象类型的变量.一个Dataflow将一些过滤的行导入记录集,并且此记录集存储在对象变量中.

在完全独立的数据流中,我需要使用该记录集作为源.所以我创建了一个脚本组件并告诉它它将是一个数据源.

我把它设置为我需要的三个输出列.我的问题是,如何让记录集中的每一行在脚本组件中创建一个新行?

我将记录集变量作为只读变量传递,当我尝试将变量传递到每一行时我无法做到,因为变量没有定义get枚举器方法.

因此,我无法将每一行打印到这些列中,并且不能将我的脚本组件用作数据源.

有没有其他人遇到类似的情况?我做了一些愚蠢的事情,还是你用另一种方式做事?

作为一个说明,我在脚本和Visual Studio 2008中使用C#

Rhy*_*ysW 7

所以我环顾了一下,找到了我的问题的VB解决方案,我把它翻译成C#,现在编译并按预期运行.我使用的代码是这样的:

    DataTable datatable = new DataTable();
    System.Data.OleDb.OleDbDataAdapter oAdapter = new System.Data.OleDb.OleDbDataAdapter();

    oAdapter.Fill(datatable,ReadOnlyVariables["User::XXXXX"]);

    foreach (DataRow row in datatable.Rows)
    {
        Output0Buffer.AddRow();
        Output0Buffer.CoverAmount = Convert.ToInt32(row["XXXX"].ToString());
    } 
Run Code Online (Sandbox Code Playgroud)

对于任何面临类似问题的人!

感谢大家的帮助


bil*_*nkc 5

我基于Andy Leonard的增量加载框架的旧版本做了类似的事情.我们的子包填充记录表明有多少新,改,不变,等行我们有计数.在父包中,我们测试该对象以确保在我们使用它之前已经填充了该对象.我要跳到一个会议,所以这赦免代码,它并不完全解决您的特定需求,但在正确的方向有希望提供了坚实的推,直到我能回来并针对你的情况.我在那里有伪代码,你想要做的事情.

    public void Main()
    {
        bool debug = Convert.ToBoolean(Dts.Variables["Debug"].Value);
        string taskName = string.Empty;
        string packageName = string.Empty;
        string sourceName = string.Empty;
        bool fireAgain = false;

        taskName = Convert.ToString(Dts.Variables["TaskName"].Value);
        packageName = Convert.ToString(Dts.Variables["PackageName"].Value);
        // Fix this by defining and passing in params
        sourceName = Convert.ToString(Dts.Variables["TaskName"].Value);

        System.Data.OleDb.OleDbDataAdapter adapater = null;
        System.Data.DataTable table = null;
        System.Data.DataColumn column = null;
        System.Data.DataRow row = null;
        string message = string.Empty;

        object rowCounts = null;
        rowCounts = Dts.Variables["RowCounts"].Value;
        table = new DataTable();

        try
        {
            // Get us out of this crazy thing - should only be an issue
            // first pass through
            if (rowCounts == null)
            {
                Dts.TaskResult = (int)ScriptResults.Success;
                return;
            }
        }
        catch (Exception ex)
        {
            throw new Exception("Failed here");
        }

        adapater = new System.Data.OleDb.OleDbDataAdapter();
        try
        {
            // This works if we pass in a dataset
            //adapater.Fill(table, Dts.Variables["RowCounts"].Value);
            adapater.Fill(table, rowCounts);
            // TODO: Enumerate through adapter
            // Call Output0Buffer.AddRow();
            // and Output0Buffer.MyColumn.Value = adapter[i].value // possibly casting to strong type
        }
        catch (Exception ex)
        {
            try
            {
                // This works if we use a datatable
                System.Data.DataSet ds = null;
                //ds = (DataSet)Dts.Variables["RowCounts"].Value;
                ds = (DataSet)rowCounts;
                table = ds.Tables[0];
                // TODO: Enumerate through datatable as we do with adapter

            }
            catch (Exception innerException)
            {
                // continue to swallow exceptions
            }
            Dts.Variables["ValidCounts"].Value = false;

            // trap "Object is not an ADODB.RecordSet or an ADODB.Record
            // parse ex.Message
            if (ex.Message.Contains("System.ArgumentException: "))
            {
                System.Text.StringBuilder exceptionMessage = null;
                exceptionMessage = new System.Text.StringBuilder();
                exceptionMessage.Append(ex.Message);
                exceptionMessage.Replace("\nParameter name: adodb", string.Empty);
                exceptionMessage.Replace("System.ArgumentException: ", string.Empty);

                if (exceptionMessage.ToString() != "Object is not an ADODB.RecordSet")
                {
                    Dts.Events.FireInformation(0, string.Format("{0}.{1}", packageName, taskName), exceptionMessage.ToString(), string.Empty, 0, ref fireAgain);
                }
            }
        }

        Dts.Variables["ValidCounts"].Value = false;
        if (table.Rows.Count > 0)
        {
            Dts.Variables["ValidCounts"].Value = true;
        }

        if (debug)
        {
            message = string.Format("SourceName:  {0}\nValidCounts:  {1}", sourceName, false);
            //System.Windows.Forms.MessageBox msgBox = null;
            //msgBox = new MessageBox();
            System.Windows.Forms.MessageBox.Show(message, string.Format("{0}.{1}", packageName, taskName));
            //MessageBox(message, string.Format("{0}.{1}", packageName, taskName));
        }

        Dts.TaskResult = (int)ScriptResults.Success;
    }
Run Code Online (Sandbox Code Playgroud)