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

Recommended Answers

All 5 Replies

-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.

sorry. im getting a hard time on this

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?

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.

Be a part of the DaniWeb community

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