0

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

3
Contributors
2
Replies
9
Views
3 Years
Discussion Span
Last Post by Reverend Jim
0

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
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.