我有一个名为 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
由于某种原因,我的输出始终为0
答案 0 :(得分:1)
这是在数据流任务中,是吗?您无法在脚本转换中修改变量,至少在processinputrow子例程中是这样。
幸运的是,似乎你正在做的修改类型 - 只是在不同的子程序中。
Donald Farmer的我的SSIS Scripting Beta书距离我有一千英里,所以请原谅这段代码的不精确。重要的是,您只能从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