Save byte array in sql server
If it's always going to be the same length, then binary(length)
would be suitable. If it's going to vary in length, use varbinary(maxlength)
.
binary and varbinary.
And, as @p.s.w.g says, you pass it from code by placing it into a suitable parameter.
Just use a byte[]
the same way you would any other parameter, specifying SqlDbType.Binary
as the parameter type. Here a sample in C#
// Generate your password hash some way
byte[] passwordHash = new byte[] { 0x0, 0x1, 0x2 ... };
...
command.Parameters.Add("@passwordHash", SqlDbType.Binary);
command.Parameters["@passwordHash"].Value = passwordHash;
Or if you prefer VB.NET
' Generate your password hash some way
Dim passwordHash As Byte() = New Byte() { &H0, &H1, &H2 ... }
...
command.Parameters.Add("@passwordHash", SqlDbType.Binary)
command.Parameters("@passwordHash").Value = passwordHash