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

Scenario:

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.

Solution:

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.

9 comments:

  1. Demasiado bueno el post... gracias

    ReplyDelete
    Replies
    1. IEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.

      IEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.

      corporate training in chennai corporate training in chennai

      corporate training companies in india corporate training companies in india

      corporate training companies in chennai corporate training companies in chennai

      I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai

      Delete
  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..

    ReplyDelete
  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

    ReplyDelete
  4. Great blog !It is best institute.Top Training institute In chennai
    http://chennaitraining.in/devops-training-in-chennai/
    http://chennaitraining.in/datastage-training-in-chennai/
    http://chennaitraining.in/abinitio-training-in-chennai/
    http://chennaitraining.in/pentaho-training-in-chennai/
    http://chennaitraining.in/msbi-training-in-chennai/
    http://chennaitraining.in/informatica-mdm-training-in-chennai/

    ReplyDelete
  5. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    http://chennaitraining.in/oracle-training-in-chennai/
    http://chennaitraining.in/oracle-dba-training-in-chennai/
    http://chennaitraining.in/odi-training-in-chennai/
    http://chennaitraining.in/oracle-soa-training-in-chennai/
    http://chennaitraining.in/teradata-training-in-chennai/
    http://chennaitraining.in/informix-training-in-chennai/
    http://chennaitraining.in/sybase-training-in-chennai/
    http://chennaitraining.in/sql-server-dba-training-in-chennai/

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

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete