I'm trying to store a byte array in the database (T-SQL) and currently I'm using varbinary(max). It successfully stores the data but I don't know how to convert it back to a byte array. Anyone knows how? Am I using the right datatype in the database?
StoreTestData(Encoding.ASCII.GetBytes("test123".ToCharArray()));
Results in 0x74657374313233
How to I get my result into a byte[] again?
I believe you can find the answer to this question here:
C# ByteArray to string conversion and back
Just cast the reader object back to a byte array.
In this case the database field "logo" is a varbinary(MAX)
...
SqlDataReader reader = cmd.ExecuteReader();
byte[] tempLogo = (byte[])(reader["logo"]);
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With