Skip to content

Instantly share code, notes, and snippets.

@kmoormann
Created August 31, 2012 18:58
Show Gist options
  • Save kmoormann/3557393 to your computer and use it in GitHub Desktop.
Save kmoormann/3557393 to your computer and use it in GitHub Desktop.
Iterate over a result set in SSIS
//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