Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to insert an image into sql server 2005 from windows applications
Posted

Create a Image field in your database.
Load the Image from the disk: Image.FromFile will do it for you.
Connect to your database, with an SqlConnection:
using (SqlConnection con = new SqlConnection(myConnectionString))
   {
   con.Open();
   using (SqlCommand cmd = new SqlCommand("INSERT INTO myTable (imageColumnName) VALUES (@IM)", con))
      {
      MemoryStream ms = new MemoryStream();
      myImage.Save(ms,System.Drawing.Imaging.ImageFormat.Jpg);
      cmd.Parameters.AddWithValue("@IM", ms.ToArray());
      cmd.ExecuteNonQuery();
      }
   }
 
Share this answer
 
 
Share this answer
 
Comments
CS2011 11-Jul-11 5:13am    
Good article. 5+

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