Reputation: 87
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?
Upvotes: 4
Views: 25438
Reputation: 5306
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"]);
...
Upvotes: 1
Reputation: 723
I believe you can find the answer to this question here:
C# ByteArray to string conversion and back
Upvotes: 4