试图在SSIS中使用脚本来分离第一个和第一个姓氏分为多个列

时间:2016-01-13 21:57:43

标签: ssis ssis-2012

提前感谢您的意见。我对SSIS中的脚本任务不是很熟悉,请随意提出尝试完成同样事情的其他方法。我试图将First,Last和偶然中间的首字母(目前在一列中)分成三部分。我发现我的脚本似乎对其他人起作用并且相对简单但是当我执行包时,我在脚本组件步骤中得到以下错误:"对象引用未设置为对象的实例" .-------- at ScriptMain.Input0_ProcessInputRow(Input0Buffer Row)    在UserComponent.Input0_ProcessInput(Input0Buffer Buffer)    at UserComponent.ProcessInput(Int32 InputID,String InputName,PipelineBuffer Buffer,OutputNameMap OutputMap)    在Microsoft.SqlServer.Dts.Pipeline.ScriptComponent.ProcessInput(Int32 InputID,PipelineBuffer buffer)    在Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID,PipelineBuffer buffer)

输入是excel文件,输出是oledb sql表。其中的脚本代码全部在此处:

#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
 using Microsoft.SqlServer.Dts.Runtime.Wrapper;
 #endregion


 [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
 public class ScriptMain : UserComponent
 {

/// You can remove this method if you don't need to do anything here.
/// </summary>
public override void PreExecute()
{
    base.PreExecute();
    /*
     * Add your code here
     */
}

/// <summary>
/// This method is called after all the rows have passed through this  
///
/// You can delete this method if you don't need to do anything here.
/// </summary>
public override void PostExecute()
{
    base.PostExecute();
    /*
     * Add your code here
     */
  }




    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        var names = Row.NAME.Split(' ');

        //if lenght is two, not middle skip the middle name
        if (names.Length == 2)
        {
            Row.FirstName = names[0];
            Row.LastName = names[1];
        }
        else if (names.Length == 3)
        {
            Row.FirstName = names[0];
            Row.MiddleName = names[1];
            Row.LastName = names[2];
        }

    }
}

1 个答案:

答案 0 :(得分:0)

我知道这是一个非常古老的帖子,但我遇到了类似的问题。

没有充分理由我弹出这个错误,向后工作我删除了脚本中的所有代码,然后是所有输入列,但仍然收到错误。

最终我将我的所有代码都复制了出来,删除了脚本任务添加了一个新任务,我的代码重新加入,并且它运行得很好。

如果这仍然是一个问题,请尝试一下。