Created
August 31, 2012 18:58
-
-
Save kmoormann/3557393 to your computer and use it in GitHub Desktop.
Iterate over a result set in SSIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//be sure to reference System.Xml; | |
//need a using using System.Data.OleDb; | |
//set up an adapter and a data table to iterate over | |
var resultsAdapter = new OleDbDataAdapter(); | |
var resultsTable = new DataTable(); | |
resultsAdapter.Fill(resultsTable, Dts.Variables["ZipCodesResultSet"].Value); | |
var list = new StringBuilder(); | |
int count = 0; | |
foreach (DataRow row in resultsTable.Rows) | |
{ | |
var zip = row[0].ToString(); | |
if (count == 0) | |
list.AppendFormat("{0}", zip); | |
else | |
list.AppendFormat(", {0}", zip); | |
count++; | |
} | |
Dts.Variables["ZipCodeList"].Value = list.ToString(); | |
// TODO: Add your code here | |
Dts.TaskResult = (int)ScriptResults.Success; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment