Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing binary data into database
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Passing binary data into database
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01634652
Message ID:
01634652
Views:
43
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.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform