Search code examples
c#sqllistssisrecordset

SSIS - how to transform a Recordset as a result of an "Execute SQL Task" into a List<string>


Having a result from "Execute SQL Task" step in an SSIS package, how to transform the result(RecordSet) into List ? (result of the sql script: 1 nvarchar column)

Step 1: "Execute SQL Task", script: "select Name from MyTable", ResultSet: "Full result set", mapped "0" to variable "User::Names"

Step 2: ?

Step 3: Using a variable "User::NameList" of type List containing all values selected in script from 1st line.


Solution

  •  public void Main()
        {
            var dt = new DataTable();
    
            new OleDbDataAdapter().Fill(dt, this.Dts.Variables["User::Names"].Value);
    
            var list = dt.Rows.OfType<DataRow>().Select(i => i[0].ToString()).ToList();
    
            this.Dts.Variables["User::NameList"].Value = list;
    
            this.Dts.TaskResult = (int)ScriptResults.Success;
        }