Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i try to save the image in sql it shows $%# this type of data in column of image.

What I have tried:

i try alot but enable to do it.
Posted
Updated 28-Jun-20 23:02pm
Comments
Richard MacCutchan 29-Jun-20 5:01am    
You need to provide much more information about how you are saving the image, and how you are retrieving it from the database.
Member 14552976 29-Jun-20 5:06am    
i am retrieving the image in mvc application.
RedDk 30-Jun-20 23:09pm    
I always try ALL OF THEM (varbinary, nvarchar, varchar, blob, etc) then when I find NOTHING works, rethink th eoriginal problem. As stated beneath here in Solution 1, you're trying to tilt the untiltable if what you think is yeah-wide (bytes) turns out to be yeah-wide-x-2/etc. Like trying to guess what the x and y of a specific image file in it's RAW state by testing every dimensional possibility.

1 solution

Don't try to save images in NVARCHAR (or VARCHAR) columns: they are for text, not binary data. Instead use a VARBINARY column, or convert your image to Base64 and store that - be aware that you will both need a lot more space to do that, and need to convert it back before you can use it. VARBINARY is a better option.
 
Share this answer
 
Comments
Member 14552976 29-Jun-20 5:05am    
if i try to save it in varbianary it gives error when i try to run the mvc application which gets the data in string form.
OriginalGriff 29-Jun-20 5:13am    
Then you need to look at your MVC application and see what it is doing with the data - if it's expecting binary data in a text field, then it's in for a corrupt image shock: treating it as Unicode data will really mess up images as it gets translated between UTF-8 and UTF-16 via characters that don't exist ...

It may be expecting a text version of the image - Base64 is common - but then it will "decode" the data to a "proper" image and you need to know how it does that in order to save it in the same format.
Member 14552976 29-Jun-20 5:16am    
now i want to save it in nvarchar datatype because i am retrieving it as a string on controller side .if i dont do that it will result in errors.
OriginalGriff 29-Jun-20 5:42am    
No. As I explained, you need to check what the other end is doing and do something complimentary or you will just give yourself even more problems.
Member 14552976 30-Jun-20 3:05am    
does there is any way to save it ai nvarchar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900