Click here to Skip to main content
15,306,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to work with an application that involves storing pictures in the database. At first, i was storing the images in the folder and the names of the pictures in the database so that i can get a picture by retrieving the name of the picture from the database. But problems started to arise recently when the location of the picture got change.
So I really need help in how to insert and retrieve pictures from a mysql database.
I also need help about the correct data type to use, whether blob, verbinary or what.

I will really appreciate it if anyone can help out.

Below link might help you

Save An Image Into SQL Server 2000 Database[^]
You should correct data type ,"longblob".

private static byte[] ImageToByteMenthod(Image img)
   byte[] imageb={};
     MemoryStream imgStream = new MemoryStream();
     img.Save(imgStream,ImageFormat.Bmp); //Gif,Jpeg
     //To do
   return imageb;

private static Image ByteToImage(byte[] data)
   MemoryStream ms = new MemoryStream(data);
   Image img = Image.FromStream(ms);

   return img;

private void Demo()
   Bitmap bitmap = new Bitmap(this.pictureBox1.Image);
   //TO DO
   ModelLayer.Product product = new ModelLayer.Product();
   //... = ImageToByteMenthod(bitmap);

  // Insert into DB...

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