store binary data in SQL text column

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
 
J

Jon Skeet [C# MVP]

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.
 
P

PearCZ

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top