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?
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;
}
First, you must decide in which encoding you are going to encode your string. If you don't care, I recommend using:
Little Endian UTF-16 for performance, since .NET strings are stored in that encoding
System.Text.Encoding.Unicode.GetBytes("MyString");
UTF-8 for storage
System.Text.Encoding.UTF8.GetBytes("MyString");
Consider reading more about encoding here: Character Encoding in .NET
You should NOT use the answer provided here . Read the whole discussion there to understand why. The answer is for a very specific use case and a somewhat educational one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With