hope hope - 6 months ago 33
SQL Question

How to insert Image to database from picturebox

I have a

PictureBox
and I want to save its picture in a SQL Server database into a
VarBinary
column

Answer

I didnt exactly get what you meant but here is a piece of code you can use for inserting an image into database from picture box.

Image img = picturebox1.Image();
byte[] arr;
ImageConverter converter = new ImageConverter();
arr=(byte[])converter.ConvertTo(img, typeof(byte[]));

command.CommandText = "INSERT INTO ImagesTable (Image) VALUES('" + arr +    "')";
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
Comments