Click here to Skip to main content
15,892,805 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello. I have a table with 3 columns:
Name Char(50)
Location Char(50)
Image(text)

How can I save an image in a text datatype? how's the conversion will be? Thanks for your help in advance. Using C#, SQL-Server, Windows Form Application

What I have tried:

It's my first time to hear that images can be saved in a text data type so I have no idea what to try yet. Sorry.
Posted
Updated 12-Aug-17 20:27pm
v2
Comments
Member 13353619 13-Aug-17 3:02am    
https://www.youtube.com/watch?v=nbRT2mMEqkE (Credits to owner)

This is what i want to happen but also to save it in the database. BTW the video is for VB.Net and what im working is windows app form

Store or Save images in SQL Server[^]
Storing and Retrieving Images from SQL Server Using Strored Procedures and C#[^]

And if you extend your search beyond CP, you will find thousands of answers...
 
Share this answer
 
Comments
Member 13353619 13-Aug-17 2:26am    
I've already seen those links and as I said into my question "How can I can save and retrieve image to SQL server database's text(data type) column." Those links will show you how to save it in an IMAGE FIELD(IMAGE DATATYPE). What I'm having trouble is how can I save an image/picture in a TEXT FIELD(TEXT DATA TYPE IN THE DB). Think there's going to be a conversion of image/pic to text or what...
Don't store images in text columns, you have to convert the image to something like Base64 to avoid problems - and that gets very inefficient as far as space is concerned.
Instead use a VARBINARY column, and insert the bytes from the image directly via a parameterised query.
This shows the code to do it: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]
 
Share this answer
 
Comments
Member 13353619 13-Aug-17 2:35am    
Ohhh I see. Thank you very much, but the company asks me to do is save it into a text column just like how they do it in FoxPro... I am a newly hired and database is created by them so I cannot just alter the table's text column and changed it to varbinary xD
OriginalGriff 13-Aug-17 4:27am    
If you want it in a text field, you will need to convert it to Base64 or similar, as I said.
https://msdn.microsoft.com/en-us/library/dhx0d524(v=vs.110).aspx
But ... it's a piss-poor design decision, particularly if the images get large. It wastes space in the DB, it increases bandwidth usage, it means more processing needed to store and retrieve it, ... generally not a good idea, even if it historically may have been done for good reasons in a very old application.
Member 13353619 13-Aug-17 8:52am    
I agree with you and Thank you very much for the help. Godbless you :)
OriginalGriff 13-Aug-17 9:52am    
You're welcome!

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