The SSIS package consists of one control flow and one or more data streams (optional. The following diagram shows the control flow with one container and six tasks.
Five of these tasks are defined at the package level, and one is defined at the container level. The task is located in the container. In the control flow toolbox, we can divide the control in the toolbox into two types: Container Control and task control. Now let's take a look at the controls contained in the container.
Container
1. For Loop
The for loop container is similar to the For Loop Structure in compiled languages. When a loop repeats, The for loop container calculates an expression and runs the loop repeatedly until the expression returns false.
The for container is easy to use. Here is a brief introduction to the usage.
> Bids development tools open the created "ssisdemo" project and create a new package. Name it "forcontainerdemo"
> Select the variable tab on the left of the tool. If this option is not available, select the "SSIS" menu on the menu and click the variable. The pop-up dialog box is as follows:
Here we can create variables by ourselves. Click the first icon in. Create a variable. After creation, you can set the data type and initial value. The result is as follows:
You can also click the second icon to delete the variable.
> After selecting the control flow tab, the Tools tab appears on the left. Open the tab and drag the for loop container to the control flow. Then drag a script task control to the for container:
> Right-click the for container and click Edit. the dialog box is displayed.
The following attributes are displayed:
Initexpression: The expression that provides the value used to initialize the loop (optional ).
Evalexpression: provides an expression for calculating whether a loop should be stopped or continued.
Assignexpression: an expression that allows you to change a condition when each loop repeats (optional ).
Name: a unique name for the For Loop container. This name is used as a label in the task icon.
Description: describes the for loop container.
Set these attributes as shown in.
The Count variable is the variable we set in the variable container. When using the variable, add "@" before it. ClickOKButton
> Drag and dropScript taskControlFor containerAnd right-click the script task> select edit. The dialog box is displayed. InReadonlyvariablesClick"..."Button.Select variable dialog box. In this dialog box, select the defined count variable. The configuration result is as follows:
> ClickEdit script button. The vs editor is displayed. Add the following code to the main function:
String COUNT = DTS. Variables ["count"]. value. tostring ();
MessageBox. Show (count );
Close the vs editor. Close at lastScript task Editor
> Right-click the "forcontainerdemo" package and selectExecution package, Result:
The dialog box appears five times. This indicates that the for container has been circulating for five times. The final execution result is as follows.
Here,For Loop containerControl introduction complete. Next we will introduce the next foreach loop container. I believe you can see the foreach word. Guess how to use the control.