Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image into SQL 2005

Status
Not open for further replies.

lance59

IS-IT--Management
Mar 6, 2007
50
0
0
US
I have this code but gives me an error on the insert statement. User selects image from file which loads into picturebox. I then pull out the image to store in SQL 2005.

Code:
If have_image = True Then
                Dim ms As New MemoryStream
                PictureBox3.Image.Save(ms, PictureBox3.Image.RawFormat)
                Dim itemImage() As Byte = ms.GetBuffer
                ms.Close()

                Dim cn2 As New SqlConnection(insert_conn_string)
                Dim objCommand2 As New SqlCommand("", cn2)
                cn2.Open()
                objCommand2.CommandText = "INSERT INTO images(stored_image,image_guid) VALUES(itemImage,'" & strGUID & "')"
                objCommand2.ExecuteNonQuery()
                cn2.Close()
                cn2 = Nothing
            End If

I believe I am not formatting the itemImage variable in the insert line, but I need help. Maybe better to pull image from file rather then picturebox?


TIA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top