Question

I have a database table PHOTOS created in Visual studio. It has id (int), filename (string) and photo filed type image. I made a form to insert current immage from PictureBox into database. Of course, since I am very inexperienced it does not work. How do you insert image into database from picturebox in c#? Thank you for answer, I know this code is wrong but I hope it gives you an idea what am I trying to do.

SqlCeCommand command = new SqlCeCommand("insert  into photos(id, photo ,filename) values (@id, @blob,@filename)", connection);
command.Parameters.AddWithValue("@blob", pictureBox1.Image);//fileBytes);
command.Parameters.AddWithValue("@filename", textBox1.Text);
command.Parameters.AddWithValue("@id", Int32.Parse(textBox2.Text));
Was it helpful?

Solution

You need to convert your image into a byte array to insert it into the DB. Here's a thread on how to do that: How to convert image in byte array Beyond that, you already have the general idea. You just use the byte[] as the parameter's value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top