Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to acheive a query thats definitely stores an image in a column and also recognises the image type and stores the type in another column.

Examples of Image Type as in : PNG, JPEG.

I would now create a table like below

CREATE TABLE [dbo].[test3](
	[ImageID] [int] IDENTITY(1,1) NOT NULL,
	[Title] [varchar](50) NOT NULL,
	[Image Type] [varchar](50) NOT NULL,
	[Image] [image] NOT NULL)


What I have tried:

Tried Googling but found nothing specific
Posted
Updated 26-Jan-19 6:09am
Comments
Bryian Tan 26-Jan-19 11:48am    
I see there is [Image Type] column to store the image type. so what the problem? Image is image right? There should be another persona to describe it.
vaibhav1800 26-Jan-19 13:53pm    
Yup True that, Just got it sorted, Thanks for your time Bryian :)

1 solution

Image type is complicated, particularly since you pass the image itself as a stream of bytes to be stored in your Image column (ref your previous question: Store image in SQL [working example for SQL server][^]) and identifying image type from the blob of data is just not really practical.

Instead, replace the Image Type column with a FileName column which includes the extension and pass that from your C# code when you save the image data. That way, when you restore it, it know what file type it should be stored in, and that should enable you identify it sufficiently.
 
Share this answer
 
Comments
vaibhav1800 26-Jan-19 13:54pm    
Hey Buddy, Umm Image Type Worked actually. Let me know if you would like to email you the code.
MadMyche 26-Jan-19 17:32pm    
It is a valid suggestion; because it will retain the original filename. IMHO you are better off saving the image to disc; space is cheap and it is better in performance in over 99% of applications

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