0

Private Sub RetrieveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RetrieveButton.Click

    conn = New MySqlConnection
    conn.ConnectionString = "server=127.0.0.1; Port=3306; user id=root; password=; database=bsit3d"
    Dim READER As MySqlDataReader
    Dim Command As New MySqlCommand

    conn.Open()

    Dim Query As String

    Query = "select * from bsit3d.form where username= '" & username.Text & "' "
    Command = New MySqlCommand(Query, conn)
    READER = Command.ExecuteReader

    Dim arrImage() As Byte

    While READER.Read

        StudentID.Text = READER.GetString("studentID")
        Lastname.Text = READER.GetString("lastname")
        Firstname.Text = READER.GetString("firstname")
        Middlename.Text = READER.GetString("middlename")
        Birthdate.Text = READER.GetString("birthday")
        Age.Text = READER.GetString("age")
        Address.Text = READER.GetString("address")
        ComboBox1.Text = READER.GetString("gender")
        Emailadd.Text = READER.GetString("emailadd")
        Religion.Text = READER.GetString("religion")
        password.Text = READER.GetString("password")

        READER.Read()
        arrImage = READER.Item("image")
        Dim mstream As New System.IO.MemoryStream(arrImage)
        PictureBox2.Image = Image.FromStream(mstream)
        READER.Close()


    End While

    MessageBox.Show("Student's information is shown.")

    conn.Close()
    conn.Dispose()
End Sub
3
Contributors
5
Replies
17
Views
1 Year
Discussion Span
Last Post by Mr.M
0

-You didn't say what error do you get from that code.
-You can store your images somewhere in a folder and only store the path to that folder in your database.

0

Sorry, I don't use your way but, did you try setting the image source to "mstream", it appears to me like you have declared "mstream" to hold the image source?

1

Check the below code. You need to pull the image.

 Dim connection As New SqlConnection("connection string here")
 Dim command As New SqlCommand("SELECT Picture FROM MyTable
 WHERE ID = 1", connection)

 connection.Open()

 Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(),
 Byte())

 connection.Close()

 Dim picture As Image = Nothing

 'Create a stream in memory containing the bytes that comprise
 the image.
 Using stream As New IO.MemoryStream(pictureData)
 'Read the stream and create an Image object.      from the data.
 picture = Image.FromStream(stream)
 End Using

Note how image is read from database before displaying.

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.