Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

SSIS - ForEach From Variable Enumerator Expand / Collapse
Author
Message
Posted Monday, December 21, 2009 4:25 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 10, 2011 1:45 PM
Points: 11, Visits: 46
Hi,

I'm using ForEach Loop container and selected "ForEach From Variable Enumerator" option. I created a variable of System.Object(User::Collection) and selected the "User::Collection" for Variable dropdown in Enumertaor configuration.

I have a script task that populates the "User::Collection" variable. The code is listed below

Public Sub Main()
'
' Add your code here
'
Dim arr As New ArrayList
arr.Add("D:\Tests\a.txt")
arr.Add("D:\Tests\b.txt")
Dts.Variables("User::Collection").Value = arr

Dts.TaskResult = Dts.Results.Success
End Sub

The script task that populates the collection is connected to the foreach loop. In the foreach loop, there is a script task that reads the indexed value and displaying the value. I'm able to read only the first value and not all the other values in the collection. Any thoughts?

Thanks in Advance



Post #837644
Posted Monday, December 21, 2009 6:07 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 12:08 AM
Points: 35,366, Visits: 31,901
In plain English, what is it that you're trying to do?

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #837677
Posted Tuesday, December 22, 2009 7:59 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 10, 2011 1:45 PM
Points: 11, Visits: 46
Hi,

I'm trying to use "ForEach From Variable" Enumerator. In the foreach loop, I'm able to read only the first item from the collection.

How can I access all the items in the collection?

Thanks,
Post #837936
Posted Tuesday, December 22, 2009 8:38 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, October 3, 2014 9:25 AM
Points: 895, Visits: 2,432
Like Jeff, I'm not sure what it is you are trying to do.

what is the purpose of the package? Is it to parse through a list of files?, to loop through a dataset?


_________________________________________________________________________
SSC Guide to Posting and Best Practices
Post #837957
Posted Tuesday, December 22, 2009 8:46 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, April 11, 2014 7:30 AM
Points: 346, Visits: 518

Works fine for me.

How are you trying to access the variable from the object? Did you define another variable and mapped in for each loop?



--
Sabya
Post #837965
Posted Tuesday, December 22, 2009 8:49 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, April 11, 2014 7:30 AM
Points: 346, Visits: 518

The only additional thing I did was to define a variable user::fileJustFound (string).

On for each loop container -> variable mapping -> mapped user::fileJustFound as 0 (the only one variable)

Then used a simple file system task to delete the file with name = user::fileJustFound....

It looped through successfully and deleted files. Wondering if you are missing this part of mapping the variable appropriately.



--
Sabya
Post #837968
Posted Tuesday, December 22, 2009 8:57 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, October 3, 2014 9:25 AM
Points: 895, Visits: 2,432
sabyasm (12/22/2009)

The only additional thing I did was to define a variable user::fileJustFound (string).

On for each loop container -> variable mapping -> mapped user::fileJustFound as 0 (the only one variable)

Then used a simple file system task to delete the file with name = user::fileJustFound....

It looped through successfully and deleted files. Wondering if you are missing this part of mapping the variable appropriately.



I would ask whats the point of using the Script Task if its a simple File directory parser, why not simply use the built in file Enumerator thats provided in the Task.



_________________________________________________________________________
SSC Guide to Posting and Best Practices
Post #837974
Posted Tuesday, December 22, 2009 9:00 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, April 11, 2014 7:30 AM
Points: 346, Visits: 518

what is the purpose of the package? Is it to parse through a list of files?, to loop through a dataset?


You already asked ...

I was more curious and tried to help on why it wasn't working - rather than why he is using this approach..


--
Sabya
Post #837978
Posted Tuesday, December 22, 2009 9:08 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, October 3, 2014 9:25 AM
Points: 895, Visits: 2,432
sabyasm (12/22/2009)

what is the purpose of the package? Is it to parse through a list of files?, to loop through a dataset?


You already asked ...

I was more curious and tried to help on why it wasn't working - rather than why he is using this approach..


Touche....



_________________________________________________________________________
SSC Guide to Posting and Best Practices
Post #837986
Posted Tuesday, December 22, 2009 9:36 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 10, 2011 1:45 PM
Points: 11, Visits: 46
Jason Lees-299789 (12/22/2009)
Like Jeff, I'm not sure what it is you are trying to do.

what is the purpose of the package? Is it to parse through a list of files?, to loop through a dataset?


I need to get a list of Names from the database and use the list it in multiple tasks of the package. So I'm getting the names from the database and storing them in to a array list. The array list is stored in to a variable of System.Object. This will avoid the trips to the database to get the names every time I need them.

I'm trying to figure out how to read the names from the Variable(User::Collection) using the ForEach From Variable Enumerator.

Hope this helps.
Post #838007
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse