Hi guys,
Im very new to vb.net. I have this project that I'm working on Just to get more insight and appreciate programming.
Now the problem I'm getting now is how to save the picture already selected to my picture box into the database (sql-server)

this is my datase:
 memberID   varchar(10)
 firstName  varchar(50)
 lastName   varchar(50)
 picture    image

I want the save button (btnSave) on my vb to save their respective values into the database directly

thanks in advance

Recommended Answers

All 2 Replies

Your PictureBox stores an Image object, which is not directly compatible with a SQL Server image column. What you need to do is convert the Image object to an array of bytes for storage:

Using ms As New MemoryStream()
    PictureBox1.Save(ms, ImageFormat.Jpeg)

    Dim data As byte() = ms.ToArray()

    ' Save data to your picture column
End Using

Loading the image back from a database follows a similar pattern:

Dim data As byte()

' Retrieve your picture column into data

Using ms As New MemoryStream(data)
    PictureBox1.Image = Image.FromStream(ms)
End Using

There is a more complete example here. I wrote the code to handle saving/retrieving Word documents but the same code works for any type of file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.