这是sql 2005.
@H_403_2@我在数据流任务中有一个脚本组件.我想从输入列中读取并将数据写入全局用户变量.
@H_403_2@我已经设置了输入列,并将我的全局用户变量作为ReadWriteVariable添加到脚本组件属性中.
@H_403_2@这是我的代码,我只是想在这里改变全局用户变量的值,但它不起作用.当我在另一个任务中写出变量的值时,它仍然具有默认值:
Imports System Imports System.Data Imports System.Math Imports Microsoft.sqlServer.Dts.Runtime Imports Microsoft.sqlServer.Dts.Pipeline.Wrapper Imports Microsoft.sqlServer.Dts.Runtime.Wrapper Public Class ScriptMain Inherits UserComponent Dim updatesql As String Public Sub Main() Dim vars As IDTSVariables90 VariableDispenser.LockOneForWrite("sql_ATTR_Update",vars) vars("sql_ATTR_Update").Value = "Test" vars.Unlock() End Sub Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) 'updatesql = Row.ITMID + Row.PRCCAT End Sub End Class@H_403_2@我也试过没有运气:
Me.ReadWriteVariables("sql_ATTR_Update").Value = "Test"
解决方法
我想到了.
@H_403_2@来自MS:
@H_403_2@In Script component code,you use@H_403_2@@L_502_0@ @H_403_2@看起来Dts仅在Script Task中可用. @H_403_2@这是代码的样子:
typed accessor properties to access
certain package features such as
variables and connection managers. @H_403_2@The PreExecute method can access only
read-only variables. The PostExecute
method can access both read-only and
read/write variables. @H_403_2@For more information about these
methods,see Coding and Debugging the
Script Component.
Imports System Imports System.Data Imports System.Math Imports Microsoft.sqlServer.Dts.Runtime Imports Microsoft.sqlServer.Dts.Pipeline.Wrapper Imports Microsoft.sqlServer.Dts.Runtime.Wrapper Public Class ScriptMain Inherits UserComponent Dim updatesql As String Public Overrides Sub PostExecute() Me.ReadWriteVariables("sql_ATTR_Update").Value = "Test" End Sub Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) 'updatesql = Row.ITMID + Row.PRCCAT End Sub End Class