Export (0) Print
Expand All

Variable.DataType Property

Gets a TypeCode enumeration that describes the data type of the variable. This property is read-only.

Namespace:  Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property DataType As TypeCode 
	Get
'Usage
Dim instance As Variable 
Dim value As TypeCode 

value = instance.DataType

Property Value

Type: TypeCode
A TypeCode enumeration that represents the data type of the variable.

The DataType of a variable is not set explicitly, but is inferred from the initial value assigned to the variable, and cannot be changed afterward.

The following example creates a package, adds a ForEachLoop, and adds a variable to the Variables collection of the ForEachLoop. It then retrieves and sets properties on the variable and displays them for viewing, including the DataType.

Shared Sub Main(ByVal args() As String) 
    Dim p As New Package()
    ' Add a sequence to the package executables collection
    Dim seq As Sequence = CType(p.Executables.Add("STOCK:SEQUENCE"), Sequence)
    ' Add a ForEachLoop to the Sequence
    Dim feLoop As ForEachLoop = CType(seq.Executables.Add("STOCK:FOREACHLOOP"), ForEachLoop)
    
    ' Add a variable, v, to the variable collection
    ' of the ForEach loop.
    Dim v As Variable = feLoop.Variables.Add("v", False, "global", 100)
    
    '  Get and set different variable properties
    ' Creation Name (read-only)
    Dim createName As String = v.CreationName
    
    ' Description (read/write)
    v.Description = "my new v Description"
    Dim vDesc As String = v.Description
    
    ' ID (read-only)
    Dim vID As String = v.ID
    
    ' Name (read/write)
    Dim oldName As String = v.Name
    v.Name = "my_new_V_name"
    Dim newName As String = v.Name
    
    ' Namespace (read/write)
    Dim oldNamespace As String = v.Namespace
    v.Namespace = "my_new_v_Namespace"
    Dim newNamespace As String = v.Namespace
    
    ' Properties (read-only)
    Dim pmCount As Integer = v.Properties.Count
    
    ' Qualified Name (read-only)
    Dim QName As String = v.QualifiedName
    
    ' RaiseChangedEvent (read/write)
    Dim oldraiseChEvt As [Boolean] = v.RaiseChangedEvent
    v.RaiseChangedEvent = True
    Dim raiseChangedEvent As [Boolean] = v.RaiseChangedEvent
    
    ' Read-only (read/write)
    Dim vReadOnly As [Boolean] = v.ReadOnly
    v.ReadOnly = True
    Dim newVReadOnly As [Boolean] = v.ReadOnly
    
    ' System Variable (read-only)
    Dim sysVar As [Boolean] = v.SystemVariable
    
    ' Type (read-only)
    Dim type As TypeCode = v.DataType
    
    ' Value (read/write)
    Dim vValue As [Object] = v.Value
    
    Console.WriteLine("The variable properties are: ")
    Console.WriteLine("Creation Name   = {0}", createName)
    Console.WriteLine("Description        = {0}", vDesc)
    Console.WriteLine("ID                     = {0}", vID)
    Console.WriteLine("Old name, new name = {0}, {1}", oldName, newName)
    Console.WriteLine("Old namespace, new namespace = {0}, {1}", oldNamespace, newNamespace)
    Console.WriteLine("Properties count   = {0}", pmCount)
    Console.WriteLine("Qualified Name     = {0}", QName)
    Console.WriteLine("old RaiseEvent, new RaiseEvent = {0}, {1}", oldraiseChEvt, raiseChangedEvent)
    Console.WriteLine("old read-only, new read-only = {0}, {1}", vReadOnly, newVReadOnly)
    Console.WriteLine("System Variable    = {0}", sysVar)
    Console.WriteLine("Type               = {0}", type)
End Sub 

Sample Output:

The variable properties are:

Creation Name =

Description = my new v Description

ID = {622CF328-55D7-4E81-9385-9C1F8450511E}

Old name, new name = v, my_new_V_name

Old namespace, new namespace = global, my_new_v_Namespace

Properties count = 12

Qualified Name = my_new_v_Namespace::my_new_V_name

old RaiseEvent, new RaiseEvent = False, True

old read-only, new read-only = False, True

System Variable = False

Type = Int32

Community Additions

ADD
Show:
© 2015 Microsoft