SSIS – Read C# ‘List’ collection in ‘Execute SQL Task’
In one of our integration requirements, we had to read the ‘List<>’ collection values, which was set in ‘Script Task’ control and pass to ‘Execute SQL Task’ control.
In this article I am going to list out the step by step process to set and get the ‘List<>’.
Assume that you have a collection List<string> which holds ‘Product Names’
var listProducts = new List<string>() {“Product1″, ” Product2″, ” Product3″};
Lets see how to loop through and read the ‘Product names’ and pass to ‘Execute SQL Task’.
Required SSIS components:
- A SSIS ‘Variable’ (i.e., varProducts) of type ‘Object’ to set the ‘List<>’ object in ‘Script Task’ control
- A SSIS ‘Variable’ (i.e., varProductName) of type ‘String’ to set the ‘Product Name’ for each List<> value.
- ‘Foreach Loop container’ to parse and read the ‘List<>’
Steps:
- Choose ‘varProducts’ as ‘ReadWriteVariables’
- In ‘ScriptTask’ set ‘listProduct’ object to ‘varProducts’ variable.
- var listProducts = new List<string>() {“Product1″, ” Product2″, ” Product3″};
- Dts.Variables[“User:: varProducts”].Value = listProducts ;
- In ‘Foreach Loop container’,
- Choose ‘Enumerator’ as ‘Foreach From Variable Enumerator’
- Enumerator Variable as ‘User:varProducts’
- As the ‘List’ contain ‘Product Name’ collection, read the ‘Product Name’ to ‘varProductName’ variable. ‘Index’ 0 denotes, first value in collection (i.e., Product Name’.
- As the final step, In ‘Execute SQL Task’, map the ‘varProductName’ variable to a ‘Parameter’.
- In above screen, we are setting ‘@prodName’ parameter with ‘Product Name’ and ‘@prodName’ further used in ‘SQL Statement’ of ‘Execute SQL Task.
🙂
Advertisement
Categories: SQL
Tags: List collection, SSIS
Comments (0)
Trackbacks (0)
Leave a comment
Trackback
Stats
- 1,579,655 hits
Tweets
- RT @MikeFactorial: Big things are coming to the #CoEStarterKit. So, @ManuelaPichler_ and team are building the tension for the April releas… 2 weeks ago
- New blog post : Boost conversations using GPT in Power Virtual Agent (PVA) rajeevpentyala.com/2023/03/08/pow… 2 weeks ago
- RT @PPDevWeekly: 🔥 Going Live: Power Platform Dev Weekly 155 bit.ly/PPDevWeekly155 This week's cover story by @RajeevPentyala With gre… 2 weeks ago
- RT @caseyburke21: Pipelines is now generally available! Huge congratulations to the team and all who have supported reaching this milestone… 3 weeks ago
- New blog post : Call Dataverse actions directly in power-fx rajeevpentyala.com/2023/03/01/ste… 3 weeks ago
Join 404 other subscribers
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- [Experimental Feature] Call Dataverse actions directly in Power Fx
- [Step by Step] Power Apps | Show pop ups in Canvas App
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- God Mode - Level Up - Dynamics 365 Chrome Extension
- Set “Created On”,” Created By”, “Modified On”, “Modified By” fields using SDK/Data Import/Plug-in – Dynamics 365
- Associate/Disassociate plugin messages in CRM
- Dynamics CRM | Microsoft Power Apps | Legacy OData v2.0 Service removal date