Click here to Skip to main content
13,507,742 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello. I have a table with 3 columns:
Name Char(50)
Location Char(50)

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 12-Aug-17 19:55pm
Updated 12-Aug-17 20:27pm
Member 13353619 13-Aug-17 3:02am (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
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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...
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...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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?[^]
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.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180417.1 | Last Updated 13 Aug 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100