C# – How to convert a String to a BlobColumn in SSIS

csql serverssis

So I have a column in my SSIS Script Called Data which is of type BlobColumn

I want to assign this column to a string value.

I do the following:

Row.Data = "MyString";

but I get the following error:

Cannot implicitly convert type 'string' to
Microsoft.SqlServer.Dts.Pipeline.BlobColumn

So how do I assign a BlobColumn to a String value?

Best Answer

using the answer provided for Converting a string to byte-array without using an encoding (byte-by-byte)

I did the following:

Row.Data.AddBlobData(GetBytes("MyString"));

Where:

byte[] GetBytes(string str)
{
    byte[] bytes = new byte[str.Length * sizeof(char)];
    System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
    return bytes;
}