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

这是与SSIS相关的问题

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

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

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

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

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

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

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

所以我环顾了一下,找到了我的问题的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()); } 

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

感谢大家的帮助

我基于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; } 

我正在研究与OP相同的问题。 就我而言,我认为它是一个对象,我花了很多时间尝试将其转换为数据表。 我发现该对象已经是一个数据表,所以从SSIS脚本任务组件,我能够写出:

 DataTable dt = (DataTable)ReadOnlyVariables["User::FTP_DataPath_File_Metadata"].Value; foreach (DataRow row in dt.Rows) { CustomOutputBuffer.AddRow(); CustomOutputBuffer.FileName = row.ItemArray[0].ToString(); CustomOutputBuffer.FileLastModified = Convert.ToDateTime(row.ItemArray[1]); CustomOutputBuffer.FileSize = Convert.ToInt32(row.ItemArray[2]); } 

这使用脚本组件作为源成功地将我的“对象变量”转换为数据流。

此示例用于容纳Task Factory Secure FTP组件,该组件将“使用元数据获取文件列表”的结果保存到对象变量。