Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过SSIS中的C#脚本将派生列添加到表中_C#_.net_Ssis_Ssis 2012 - Fatal编程技术网

通过SSIS中的C#脚本将派生列添加到表中

通过SSIS中的C#脚本将派生列添加到表中,c#,.net,ssis,ssis-2012,C#,.net,Ssis,Ssis 2012,我想计算一个散列函数(使用MD5)并将一列添加到现有表中,得到结果。我正在使用SSIS中的脚本任务编写一个简短的C#脚本。 这是我的剧本: using System; using System.Data; using Microsoft.SqlServer.Dts.Pipeline.Wrapper; using Microsoft.SqlServer.Dts.Runtime.Wrapper; using System.Security.Cryptography; using System.Tex

我想计算一个散列函数(使用MD5)并将一列添加到现有表中,得到结果。我正在使用SSIS中的脚本任务编写一个简短的C#脚本。 这是我的剧本:

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    public override void PreExecute()
    {
        base.PreExecute();
        /*
         * Add your code here
         */
    }

    public override void PostExecute()
    {
        base.PostExecute();
        /*
         * Add your code here
         */
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        /*
         * Add your code here
         */
        using (MD5 md5Hash = MD5.Create())
        {
            string hash = GetMd5Hash(md5Hash, Row);
            MessageBox.Show(hash);
        }
    }

    static string GetMd5Hash(MD5 md5Hash, Input0Buffer input)
    {

        // Convert the input string to a byte array and compute the hash. 
        byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input.ToString()));

        // Create a new Stringbuilder to collect the bytes 
        // and create a string.
        StringBuilder sBuilder = new StringBuilder();

        // Loop through each byte of the hashed data  
        // and format each one as a hexadecimal string. 
        for (int i = 0; i < data.Length; i++)
        {
            sBuilder.Append(data[i].ToString("x2"));
        }

        // Return the hexadecimal string. 
        return sBuilder.ToString();
    }

}
使用系统;
使用系统数据;
使用Microsoft.SqlServer.Dts.Pipeline.Wrapper;
使用Microsoft.SqlServer.Dts.Runtime.Wrapper;
使用System.Security.Cryptography;
使用系统文本;
使用System.Windows.Forms;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
公共类ScriptMain:UserComponent
{
公共覆盖无效预执行()
{
base.PreExecute();
/*
*在这里添加您的代码
*/
}
公共重写void PostExecute()
{
base.PostExecute();
/*
*在这里添加您的代码
*/
}
公共覆盖无效Input0\u进程InputRow(Input0Buffer行)
{
/*
*在这里添加您的代码
*/
使用(MD5 md5Hash=MD5.Create())
{
string hash=GetMd5Hash(md5Hash,行);
MessageBox.Show(散列);
}
}
静态字符串GetMd5Hash(MD5 md5Hash,Input0Buffer输入)
{
//将输入字符串转换为字节数组并计算哈希。
byte[]data=md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input.ToString());
//创建新的Stringbuilder以收集字节
//并创建一个字符串。
StringBuilder sBuilder=新StringBuilder();
//循环遍历散列数据的每个字节
//并将每个字符串格式化为十六进制字符串。
for(int i=0;i
我的SSIS包如下所示: 我只是从一个只有一行的数据库中获取一个表。我想散列所有列,创建另一列并将散列结果存储在那里。我能够生成散列,但我不知道如何向结果集中添加一列并将散列的值插入该列。任何帮助都将不胜感激。 谢谢。

要按您在回复billinkc时的要求在c中指定列,您的代码如下所示:

public override void Input0\u ProcessInputRow(Input0Buffer行)
{
/*
*在这里添加您的代码
*/
使用(MD5 md5Hash=MD5.Create())
{
//string hash=GetMd5Hash(md5Hash,行);
Row.MyOutputColumn=GetMd5Hash(md5Hash,Row);
//MessageBox.Show(散列);
}
}

在脚本组件中,查看第三个选项卡,并在Output0集合中添加新的column@billinkc非常感谢。如何在脚本中为该列赋值?请参阅此答案部分。同样的步骤,然后在mbox调用的位置赋值