Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am trying to insert an image into database table called Picture.

When I try to insert a (.png) image, I get no error but when I try to insert a (.jpeg) image or others apart from (.png) then I get this error
"A generic error occurred in GDI+".

This is my code

What I have tried:

VB
btnsave ()

Try

Dim mstream as New System.IO.MemoryStream ()
PictureBox1.Image.Save(mstream, System. Drawing.Imaging.ImageFormat.Jpeg)
Dim arrImage() As Byte = mstream. GetBuffer()

sql = " Insert into Picture (Pic) & _
"Values(@pic)"

Connect()
cmd = new OledbCommand (sql,conn)

cmd.parameters.Addwithvalue("pic", arrImage)
 cmd.ExecuteNonQuery()

Catch ex As Exception 
MsgBox (ex.Message)

End Try
End Sub
Posted
Updated 2-Apr-16 10:39am
v2

1 solution

The problem isn't with saving to the database, it's with your image. I'd suggest reading up on c# - A generic error occurred in GDI+, JPEG Image to MemoryStream - Stack Overflow[^] as I bet your image is coming from a memory stream that you've already closed earlier.

Marc
 
Share this answer
 

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