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.

12 comments:

  1. Demasiado bueno el post... gracias

    ReplyDelete
  2. 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
  3. This is an awesome post. Really very informative and creative contents. oracle training in chennai

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

    ReplyDelete
  5. HI I am getting below error ,Not sure whats happening

    object is not an adodb.recordset or an adodb.record site:

    ReplyDelete
  6. If Oracle is your dream job, then we, Infycle, are with you to make your dream into reality. Infycle Technologies offers the best Oracle Training in Chennai, which offers various programs in Oracle such as Oracle PLSQL, Oracle DBA, etc., in the 200% hands-on practical training with specialized trainers in the field. Also, the mock interviews will be arranged for the candidates to face the interviews without any fear, and 100% placement assurance will be given here. To have the words above real, call 7502633633 to Infycle Technologies and grab a free demo to know moreBest Oracle Training in Chennai | Infycle Technologies

    ReplyDelete
  7. Infycle Technologies, the best software training institute in Chennai offers the leading Python course in Chennai for tech professionals, freshers, and students at the best offers. In addition to the Python course, other in-demand courses such as Data Science, Cyber Security, Selenium, Oracle, Java, Power BI, Digital Marketing also will be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.

    ReplyDelete
  8. This is a very interesting post. Thank you for posting a lot of interesting post.
    ทางเข้าเล่น igoal

    ReplyDelete
  9. Board of Secondary Education, Andhra Pradesh, (BSEAP) Going to Conducts 6th, 7th, 8th, 9th, 10th Class Examination 2023, Every year more than 16 Lakhs of Students Appeared in this Exam, AP 6th, 7th, 8th, 9th, 10th Class Exam Dates Expected to be Announce Month of Soon. AP 8th Question Paper 2023 Students Alert this Time High School & Primary Schools Study Materials and Plans a Strategic Study Routine to Score well in the Exam.

    ReplyDelete
  10. I have been working on a project for the last day and all of the other examples I have been able to find online have not been able to lay it out in a way helpful to me. Your example of "SSIS - How To Read Object Type Variable In Script Task [Script Task SSIS]" gave me exactly what I needed, and wanted to thank you for that!!!

    ReplyDelete