简体   繁体   English

SSIS读/写脚本任务中的变量

[英]SSIS read/write to variable in script task

I have a variable called Valint that i need to read/write to in a script task, but it doesn't seem to work: 我有一个名为Valint的变量,我需要在脚本任务中对其进行读/写操作,但它似乎不起作用:

public class scriptmain
inherits usercomponent

dim counter as integer
dim Valint as integer
.....


Public sub new()
counter = 0
end sub

public overrides sub input0_processintputrow(byval row as input0buffer)
Dim vars as IDTSvariables100 = nothing

Me.variableDispenser.lockforread("User::Valint")
Me.variableDispenser.GetVariables(vars)

counter = CType (vars("User:: Valint").Value, integer)
vars.Unlock()

counter +=1

Me.VariableDispenser.LockoneForWrite("User::Valint", vars)
vars("User::Valint").Value = counter
vars.Unlock()
End Sub

For some reason my output is always 0 由于某种原因,我的输出始终为0

This is in a data flow task, yes? 这是在数据流任务中,对吗? You can't modify a variable in the script transformation, at least during the processinputrow subroutine. 至少在processinputrow子例程期间,不能在脚本转换中修改变量。

Fortunately, it seems like the type of modification you are doing can be done-just in different subroutines. 幸运的是,看起来您正在执行的修改类型可以完成-只是在不同的子例程中。

My SSIS Scripting Beta book by Donald Farmer is a thousand miles from me so please forgive the imprecision of this code. 我的唐纳德·法默(Donald Farmer)编写的SSIS脚本Beta版距我有一千英里,所以请原谅此代码的不精确性。 The important thing is that you can only write to the user variable from the PostExecute event. 重要的是,您只能从PostExecute事件中写入用户变量。

public class scriptmain
inherits usercomponent

dim counter as integer
dim Valint as integer
.....


Public sub new()
counter = 0
end sub

public overrides sub input0_processintputrow(byval row as input0buffer)
    counter +=1
End Sub

Public overrides sub PostExecute()
    Dim vars as IDTSvariables100 = nothing

    Me.variableDispenser.lockforread("User::Valint")
    Me.variableDispenser.GetVariables(vars)

    counter = CType (vars("User:: Valint").Value, integer)
    vars.Unlock()
    Me.VariableDispenser.LockoneForWrite("User::Valint", vars)
    vars("User::Valint").Value = counter
    vars.Unlock()
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM