Reputation: 761
Using c# code, I have converted my byte array to a string, and then stored into a sql table using Entity framework. No issues until here.
But, if I try to see value stored inside a table using 'select' command in MSSql Server Management studio, it does show blank value in that column. If I query Len(MyColumn) then it shows a valid length.
Why I am unable see value stored?
Update: It shows a value when I right click on table -> Edit top 200 rows. But, as soon as I click on that cell, value disappears. I am using Sql server 2005.
Upvotes: 0
Views: 1117
Reputation: 127543
I have converted my byte array to a string
If you did something like message= Encoding.UTF8.GetString(myByteArray)
you likely got unprintable characters. A leading \0
can cause your string to not print. This is the wrong way to handle binary data in a SQL database.
The correct way to handle this is one of the following options (in order of preference)
varbinary
not a nvarchar
this lets you store the byte[]
directly with EF without doing any conversion at all.message= Convert.ToBase64String(myByteArray)
and myByteArray = Convert.FromBase64String(message)
Upvotes: 4