SSIS - How To Read Object Type Variable In Script Task [Script Task SSIS]


It is frequently asked question, I can read object type variable by using For-each Loop in SSIS but How  can I read the object type variable in Script Task.


Here is quick demo that will show you step by step approach to read Object Type variable in Script Task.

Step 1: ­­­­­­­­­­­­­
Create connect to your SQL Server and then use Query in Execute SQL Task as given below and save the result set to VarObject Variable that is object type variable.

Select 1 as ID, 'AAMIR' AS Name
Union All
Select 2 as ID, 'Raza' AS Name

 Set the Result Set to VarObject Variable

Step 2:
Configure Script Task as shown in snapshots for your SSIS Package

Select the Script Language and Variable you need to use in Script Task

Add the Code as shown in snapshot to your Script task

Code that you see in snapshot added by me in Script task
using System.Data.OleDb;

 OleDbDataAdapter A = new OleDbDataAdapter();
            System.Data.DataTable dt = new System.Data.DataTable();
            A.Fill(dt, Dts.Variables["User::VarObject"].Value);
// TODO: Add your code here

            foreach (DataRow row in dt.Rows)
                string ID;
                string Name;
                object[] array=row.ItemArray;
                ID = array[0].ToString();
                Name = array[1].ToString();
                // I Declare both variables ID And Name as String, So I can show in Messagebox. You can Declare ID as INT and set the value and use
                //However you want to use.
                MessageBox.Show("ID Value="+ ID +" AND Name Value=" + Name);

Final Output:
Run your SSIS Package, It is going to Run Execute SQL Task in which it will load the Result Set to VarObject Variable and then inside Script task we are using VarObject variable to read values from and displaying them.


  1. Demasiado bueno el post... gracias

  2. Thank you for excellent article.I enjoyed reading your blog!!

    Please refer below if you are looking for best Civil and Mechanical courses in Coimbatore

    AutoCAD training in Coimbatore | ArchiCAD training in Coimbatore|AutoCAD RCC Detailing training in Coimbatore|Ansys Workbench training in Coimbatore

    Keep the good work and write more like this..

  3. Thank you so much for providing a good and descriptive post about SSIS.I genuinely feel this is the best way in which one can actually get to understand some crucial technicalities of SSIS.

    SSIS Postgresql Write

  4. Great blog !It is best institute.Top Training institute In chennai

  5. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

  6. This is an awesome post. Really very informative and creative contents. oracle training in chennai

  7. This comment has been removed by the author.