Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how can i save the image path in database which has column name Image and datatype as image?
Posted

Not knowing what database you want to save your image to all I can suggest is the following:

Databases do not generally have an image datatype(not the databases I am reasonably familiar with) - so you will need to save the image as a BLOB or binary large object.
 
Share this answer
 
Comments
OriginalGriff 30-Oct-11 5:14am    
*cough* http://msdn.microsoft.com/en-us/library/ms187993.aspx *cough*
GuyThiebaut 30-Oct-11 5:22am    
Thanks - I think I've been spending too much time on Oracle databases and lost touch with Microsoft's databases.
There is a notice at the top of the page saying Microsoft is going to remove the image datatype(not using this as an excuse for my ignorance) and appear to be going the way of Oracle...
OriginalGriff 30-Oct-11 5:42am    
Yes I noticed that as well - they have changed the documentation on a varbinary (and probably the implementation as well) so that it accepts more than 8000 bytes, so it does make little sense to have two datatypes with the same storage capacity. Annoying that they did change it though.
Easy:
C#
using (SqlConnection con = new SqlConnection(connectionString))
    {
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myImage) VALUES (@IM)", con))
        {
        byte[] imageData = File.ReadAllBytes(@"F:\Temp\Picture.jpg");
        com.Parameters.AddWithValue("@IM", imageData);
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 
Yes! the SQL server has the datatype image[^], refer this for storing images:

Save An Image Into SQL Server 2000 Database[^]

hope it helps :)
 
Share this answer
 

If you want to save an "image path" why do you use a column with an image datatype. Consider to change the column datatype to a string type (like VARCHAR) and save the path as a string. It's better for performance and for the storage capacity of your database.

 
Share this answer
 
v2
Comments
Uday P.Singh 30-Oct-11 5:35am    
I agree, it doesn't make sense at all.

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