Peacegle Mayor
Peacegle Mayor

Reputation: 69

How to retrieve a blob from mysql to picturebox when i click the datagrid in vb.net

i'm making a profile database program in vb.net, every profile has a picture.its datatype is a blob How can i retrieve it to a picturebox from mysql?

Upvotes: 0

Views: 709

Answers (1)

ggdio
ggdio

Reputation: 180

Here's a simple snippet that could help you:

cmd = New SqlCommand("select photo from Information where name='" & _
              DataGridView1.CurrentRow.Cells(0).Value() & "'", con)
Dim imageData As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
If Not imageData Is Nothing Then
    Using ms As New MemoryStream(imageData, 0, imageData.Length)
        ms.Write(imageData, 0, imageData.Length)
        PictureBox1.BackgroundImage = Image.FromStream(ms, True)
    End Using
End If

Upvotes: 1

Related Questions