Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing binary data into database
Message
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01634652
Message ID:
01634668
Views:
30
>>Hi everybody,
>>
>>We have the following code which is wrong:
>>
>>
>>if (SqlDbType.VarBinary == parameterType || SqlDbType.Image == parameterType || SqlDbType.Binary == parameterType)
>>            {
>>                parameter = new SqlParameter("@" + parameterName, parameterType, parameterValue.Length);
>>
>>                // TODO: Performance test these two methods
>>                //byte[] bytes = new byte[parameterValue.Length * sizeof(char)];
>>                //System.Buffer.BlockCopy(parameterValue.ToCharArray(), 0, bytes, 0, bytes.Length);
>>                //parameter.Value = bytes;
>>
>>                parameter.Value = Encoding.UTF7.GetBytes(parameterValue);
>>            }
>>
>>The value is being passed as binary string. Do you know what should be the code to pass this info into the DB?
>>
>>Thanks in advance.
>
>What do you mean by 'wrong' - what exception do you get ?
>Why UTF7 ?

The result doesn't seem to be what is expected. I don't get exception.

This was programmed by someone else, I have no idea what the correct code should be.

We need to be able to pass
\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09
and get
0x30313233343536373839
in the DB.

I also asked a related question here

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/bfc4fd55-a215-4f18-b7b2-09185abecd78/dataadapter-doesnt-seem-to-read-the-data?forum=sqldataaccess

and here

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a80db55a-ae29-44d3-b295-11aede6a907a/sending-binary-data-to-sql-server?forum=sqldataaccess
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform