store binary data in SQL text column

  • Thread starter Thread starter PearCZ
  • Start date Start date
P

PearCZ

Hi,

I am trying to store binary data (e. g. image) in MS SQL Server 2000 column
which data type is [text]. I understand I could store binary data easily in
MS SQL [image] type but I have only [text] column available in the database
which I don't want to change.

I think the trouble is in .net data type string which actually is a unicode
string. I have an array of bytes (= binary data) which I need to pass
somehow to the stored procedure which input parameter is of type [text].
Correspondant type to SQL [text] is string in .NET to which the array of
bytes must be sooner or later and explicitly or implicitly converted. Here I
think the data is
non-reversibly changed.

Thanks in advance for any hint

Pavel
 
PearCZ said:
I am trying to store binary data (e. g. image) in MS SQL Server 2000 column
which data type is [text]. I understand I could store binary data easily in
MS SQL [image] type but I have only [text] column available in the database
which I don't want to change.

I think the trouble is in .net data type string which actually is a unicode
string. I have an array of bytes (= binary data) which I need to pass
somehow to the stored procedure which input parameter is of type [text].
Correspondant type to SQL [text] is string in .NET to which the array of
bytes must be sooner or later and explicitly or implicitly converted. Here I
think the data is non-reversibly changed.

Thanks in advance for any hint

The best (cleanest, least prone to error) way here is to use
Convert.ToBase64String and Convert.FromBase64String, in my view. There
are other ways which will take significantly less space, but are more
prone to problems.
 
Thanks, this works.

Jon Skeet said:
PearCZ said:
I am trying to store binary data (e. g. image) in MS SQL Server 2000 column
which data type is [text]. I understand I could store binary data easily in
MS SQL [image] type but I have only [text] column available in the database
which I don't want to change.

I think the trouble is in .net data type string which actually is a unicode
string. I have an array of bytes (= binary data) which I need to pass
somehow to the stored procedure which input parameter is of type [text].
Correspondant type to SQL [text] is string in .NET to which the array of
bytes must be sooner or later and explicitly or implicitly converted. Here I
think the data is non-reversibly changed.

Thanks in advance for any hint

The best (cleanest, least prone to error) way here is to use
Convert.ToBase64String and Convert.FromBase64String, in my view. There
are other ways which will take significantly less space, but are more
prone to problems.
 
Back
Top