Partager via


ScriptObjectModel.Variables Property

Returns the Variables collection of existing variables defined in the package that contains the Script task.

Espace de noms: Microsoft.SqlServer.Dts.Tasks.ScriptTask
Assembly: Microsoft.SqlServer.ScriptTask (in microsoft.sqlserver.scripttask.dll)

Syntaxe

'Déclaration
Public ReadOnly Property Variables As Variables
public Variables Variables { get; }
public:
property Variables^ Variables {
    Variables^ get ();
}
/** @property */
public Variables get_Variables ()
public function get Variables () : Variables

Valeur de propriété

The Variables collection of existing variables defined in the package that contains the Script task.

Notes

Use the Variables property of the Dts object in Script task code to access variables that are available through the ReadOnlyVariables and ReadWriteVariables properties of the task.

Exemple

The following sample of code for use inside a Script task demonstrates how to access and use variables in a Script task to determine the path of package workflow. The sample assumes that you have created integer variables named CustomerCount and MaxRecordCount and added them to the ReadOnlyVariables collection in the Script Task Editor. Set values for both variables; experiment with setting values for CustomerCount that are both higher and lower than the value of MaxRecordCount. The CustomerCount variable contains the number of customer records to be imported. If its value is greater than the value of MaxRecordCount, the Script task reports failure. When a failure occurs because the MaxRecordCount threshhold has been exceeded, the error path of the workflow can implement any required clean-up code.

Public Sub Main()

    Dim customerCount As Integer
    Dim maxRecordCount As Integer

    If Dts.Variables.Contains("CustomerCount") = True AndAlso _
        Dts.Variables.Contains("MaxRecordCount") = True Then

        customerCount = _
            CType(Dts.Variables("CustomerCount").Value, Integer)
        maxRecordCount = _
            CType(Dts.Variables("MaxRecordCount").Value, Integer)

    End If

    If customerCount > maxRecordCount Then
            Dts.TaskResult = Dts.Results.Failure
    Else
            Dts.TaskResult = Dts.Results.Success
    End If

End Sub

Sécurité des threads

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Plateformes

Plateformes de développement

Pour obtenir la liste des plateformes prises en charge, consultez Configuration matérielle et logicielle requise pour l'installation de SQL Server 2005.

Plateformes cibles

Pour obtenir la liste des plateformes prises en charge, consultez Configuration matérielle et logicielle requise pour l'installation de SQL Server 2005.

Voir aussi

Référence

ScriptObjectModel Class
ScriptObjectModel Members
Microsoft.SqlServer.Dts.Tasks.ScriptTask Namespace