No mapping exists from object type System.Drawing.Bitmap to a known managed provider native type, VB.NET

前端 未结 2 1981
南旧
南旧 2021-01-15 06:16

I have a problem saving images from PictureBox1 to my SQL server database, I\'ve done my research and found out that I have to convert my image to a byte array in order to d

2条回答
  •  醉酒成梦
    2021-01-15 06:52

    In SQL SERVER database have datatype IMAGE. Keep the column datatype as IMAGE.

    You can use the following sample code and pass Image to the below function which converts the image to byte to store in database.

    public static byte[] ImageToByte2(Image img)
            {
                byte[] byteArray = new byte[0];
                using (MemoryStream stream = new MemoryStream())
                {
                    img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                    stream.Close();
    
                    byteArray = stream.ToArray();
                }
                return byteArray;
            }
    

提交回复
热议问题