Freigeben über


SetUsageType-Methode

Maps a virtual input column object and sets its usage type.

Namespace:  Microsoft.SqlServer.Dts.Pipeline.Wrapper
Assembly:  Microsoft.SqlServer.DTSPipelineWrap (in Microsoft.SqlServer.DTSPipelineWrap.dll)

Syntax

'Declaration
Function SetUsageType ( _
    lLineageID As Integer, _
    eUsageType As DTSUsageType _
) As Integer
'Usage
Dim instance As IDTSVirtualInput100
Dim lLineageID As Integer
Dim eUsageType As DTSUsageType
Dim returnValue As Integer

returnValue = instance.SetUsageType(lLineageID, _
    eUsageType)
int SetUsageType(
    int lLineageID,
    DTSUsageType eUsageType
)
int SetUsageType(
    [InAttribute] int lLineageID, 
    [InAttribute] DTSUsageType eUsageType
)
abstract SetUsageType : 
        lLineageID:int * 
        eUsageType:DTSUsageType -> int 
function SetUsageType(
    lLineageID : int, 
    eUsageType : DTSUsageType
) : int

Parameter

Rückgabewert

Typ: System. . :: . .Int32
The index of the newly created IDTSInputColumn100, or -1 if eUsageType is UT_IGNORED and the column is removed from the input column collection.

Hinweise

Custom component developers call this method, usually in their overridden implementation of the base class SetUsageType method, to add or remove columns from the input column collection of the component. If eUsageType is UT_IGNORED, and the column has previously been added to the input column collection of the component, the column index is removed. If eUsageType is UT_READONLY, or UT_READWRITE, the column is added to the collection.

This method should not be called by developers who are programmatically creating a data flow task and selecting columns for the components in the task. Instead, the SetUsageType method of the design-time instance of the component should be called. Calling this method directly bypasses the component's ability to restrict columns by data type or usage type.

Beispiele

The following code example shows a component's overridden implementation of SetUsageType that uses the virtual input's SetUsageType to add and remove columns from the input collection. In this example, the component does not allow columns to be writeable so when eUsageType is UT_READWRITE an exception occurs.

public override IDTSInputColumn100 SetUsageType(int inputID, IDTSVirtualInput100 virtualInput, int lineageID, DTSUsageType usageType)
{
    // Prevent use of read/write columns.
    if (usageType == DTSUsageType.UT_READWRITE)
        throw new Exception("Read write columns prohibited.");

    // Get the input specified by inputID.
    IDTSInput100 input = ComponentMetaData.InputCollection.GetObjectByID(inputID);

    int index = virtualInput.SetUsageType(lineageID, usageType);

    // If the index is not -1, return the column.
    // NOTE: The index that is returned is 1-based, but the input column collection is 0-based.
    if ( index != -1 )
        return input.InputColumnCollection[index-1];

    // The column was removed, so return null.
    return null;
}
Public Overrides Function SetUsageType(ByVal inputID As Integer, ByVal virtualInput As IDTSVirtualInput100, ByVal lineageID As Integer, ByVal usageType As DTSUsageType) As IDTSInputColumn100 
 If usageType = DTSUsageType.UT_READWRITE Then 
   Throw New Exception("Read write columns prohibited.") 
 End If 
 Dim input As IDTSInput100 = ComponentMetaData.InputCollection.GetObjectByID(inputID) 
 Dim index As Integer = virtualInput.SetUsageType(lineageID, usageType) 
 If Not (index = -1) Then 
   Return input.InputColumnCollection(index - 1) 
 End If 
 Return Nothing 
End Function