SSIS Dot Net Script任务 - 获取运行时包变量值

时间:2018-06-07 20:24:29

标签: .net variables ssis

在SSIS脚本任务中,如何在运行时使用DTS库或任何其他方式获取所有包级别变量值,而无需添加ReadOnlyVariables或ReadWriteVariables。我需要最新/更新的值。

1 个答案:

答案 0 :(得分:1)

 private Project GetProject(RuntimeWrapper.IDTSProject100 proj)
    {
        System.Reflection.PropertyInfo pInfo = proj.GetType().GetProperty("Project",
        System.Reflection.BindingFlags.Public |
        System.Reflection.BindingFlags.NonPublic |
        System.Reflection.BindingFlags.Instance);
        Project prj = (Project)pInfo.GetValue(proj, null);  

        return prj;
    }

==================

Sub AddSchools()

Dim i As Long 'Add Rows Variable

Dim j As Integer
    j = Range("Courses1") 'Courses of School 1
Dim k As Integer
    k = Range("Courses2") 'Courses of School 2
Dim m As Integer
    m = Range("Courses3") 'Courses of School 3
Dim n As Integer
    n = Range("Courses4") 'Courses of School 4
Dim x As Integer
    x = Range("Courses5") 'Courses of School 5
Dim y As Integer
    y = Range("Courses6") 'Courses of School 6

Dim InsertHere As Range
Set InsertHere = Worksheets("Eval Sheet").Range("A15:L15")

If k <> 0 Then '1.0) Add Rows for School 1 and then School 2
   For i = 1 To (j - 1)
        Worksheets("Eval Sheet").Activate
        With ActiveSheet
            InsertHere.Select 'Selects School 1 + Inserts (j-1) Rows here
            Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
        End With
    Next i
    If m <> 0 Then '2.0) Add Rows for School 2 and then School 3
        For i = 1 To (k - 1)
            Worksheets("Eval Sheet").Activate
            With ActiveSheet
                InsertHere.Offset(5 + (j - 1), 0).Select 'Moves Selection to School 2 + Inserts (k-1) Rows here
                Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
            End With
        Next i
        If n <> 0 Then '3.0) Add Rows for School 3 and then School 4
            For i = 1 To (m - 1)
                Worksheets("Eval Sheet").Activate
                With ActiveSheet
                    InsertHere.Offset(9 + j + k, 0).Select 'Moves Selection to School 3 + Inserts (m-1) Rows here
                    Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
                End With
            Next i
            If x <> 0 Then '4.0) Add Rows for School 4 and then School 5
                For i = 1 To (n - 1)
                    Worksheets("Eval Sheet").Activate
                    With ActiveSheet
                        InsertHere.Offset(14 + j + k + m, 0).Select 'Moves Selection to School 4 + Inserts (n-1) Rows here
                        Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
                    End With
                Next i
                If y <> 0 Then '5.0) Add Rows for School 5 and then School 6
                    For i = 1 To (x - 1)
                        Worksheets("Eval Sheet").Activate
                        With ActiveSheet
                            InsertHere.Offset(19 + j + k + m + n, 0).Select 'Moves Selection to School 5 + Inserts (x-1) Rows here
                            Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
                        End With
                    Next i
                    For i = 1 To (y - 1) '6.0) Add Rows for School 6
                        Worksheets("Eval Sheet").Activate
                        With ActiveSheet
                            InsertHere.Offset(24 + j + k + m + n + x, 0).Select 'Moves Selection to School 6 + Inserts (y-1) Rows here
                            Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
                        End With
                    Next i
                Else '5.1) Add Rows for ONLY School 5
                    For i = 1 To (x - 1)
                        Worksheets("Eval Sheet").Activate
                        With ActiveSheet
                            InsertHere.Offset(20 + j + k + m, 0).Select 'Moves Selection to School 5 + Inserts x Rows here
                            Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
                        End With
                    Next i
                Dim Delete5 As Long '5.2) Delete School 6
                    For Delete5 = 1 To 5 Step 1
                    Rows(31 + j + k + m + n + x).EntireRow.Delete
                    Next
                End If 'End of Process 5
            Else '4.1) Add Rows for ONLY School 4
                For i = 1 To (n - 1)
                    Worksheets("Eval Sheet").Activate
                    With ActiveSheet
                        InsertHere.Offset(15 + j + k, 0).Select 'Moves Selection to School 4 + Inserts n Rows here
                        Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
                    End With
                Next i
            Dim Delete4 As Long '4.2) Delete Schools 5-6
                For Delete4 = 1 To 10 Step 1
                Rows(27 + j + k + m + n).EntireRow.Delete
                Next
            End If 'End of Process 4
        Else '3.1) Add Rows for ONLY School 3
            For i = 1 To (m - 1)
                    Worksheets("Eval Sheet").Activate
                    With ActiveSheet
                        InsertHere.Offset(7 + j + k, 0).Select 'Moves Selection to School 3 + Inserts m Rows here
                        Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
                    End With
            Next i
        Dim Delete3 As Long '3.2) Delete Schools 4-6
            For Delete3 = 1 To 14 Step 1
            Rows(22 + j + k + m).EntireRow.Delete
            Next
        End If 'End of Process 3
    Else '2.1) Add Rows for ONLY School 2
        For i = 1 To (k - 1)
            Worksheets("Eval Sheet").Activate
            With ActiveSheet
                InsertHere.Offset(5, 0).Select 'Moves Selection to School 2 + Inserts k Rows here
                Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
            End With
        Next i
    Dim Delete2 As Long '2.2) Delete Schools 3-6
        For Delete2 = 1 To 19 Step 1
        Rows(17 + j + k).EntireRow.Delete
        Next
    End If 'End of Process 2
Else '1.1) Add Rows for ONLY School 1
    For i = 1 To (j - 1)
        Worksheets("Eval Sheet").Activate
        With ActiveSheet
            InsertHere.Select 'Selects School 1 + Inserts j Rows here
            Selection.EntireRow.Insert Shift = xlShiftDown, CopyOrigin:=0
        End With
    Next i
Dim Delete1 As Long '1.2) Delete Schools 2-6
    For Delete1 = 1 To 24 Step 1
    Rows(12 + j).EntireRow.Delete
    Next
End If 'End of Process 1
Worksheets("Eval Sheet").Range("A10").Select
End Sub