1
Private Sub RetrieveStaffInformation()
    CurrentRow = 0
    Connection.Open()
    Adapter = New OleDbDataAdapter("SELECT Student_Affairs_Officer.* FROM Student_Affairs_Officer ORDER BY ID", Connection)
    Adapter.Fill(DTS, "Student_Affairs_Officer")
    ShowStaffData(CurrentRow)
    Connection.Close()
    Dim StaffID As String
    Dim i, j As Integer


    txtID.Text = Login.txtUsernameORStudentID.Text
    StaffID = txtID.Text
    j = DTS.Tables("Student_Affairs_Officer").Rows.Count - 1
    i = 0
    While i <> j + 1
        If StaffID = DTS.Tables("Student_Affairs_Officer").Rows(i)("ID") Then
            ShowStaffData(i)
        End If
        i += 1
    End While

    'Dim Command As New OleDbCommand("SELECT Picture FROM Staff WHERE Staff_ID ='" & txtStaff_ID.Text & "'", Connection)
    'Command.Parameters.AddWithValue("@Staff_ID", txtStaff_ID.Text)
    'Connection.Open()
    'Dim PictureData As Byte() = DirectCast(Command.ExecuteScalar(), Byte())
    'Connection.Close()
    'Command.Dispose()
    'Dim Stream As New IO.MemoryStream(PictureData)
    'picStaff.Image = Image.FromStream(Stream)
    'Stream.Dispose()

End Sub

Private Sub ShowStaffData(ByVal CurrentRow)
    txtID.Text = DTS.Tables("Student_Affairs_Officer").Rows(CurrentRow)("ID")
    txtName.Text = DTS.Tables("Student_Affairs_Officer").Rows(CurrentRow)("Full_Name")
    PictureBox1.Image = DTS.Tables("Student_Affairs_Officer").Rows(CurrentRow)("Picture")
End Sub

I don't know why I cant retrieve pictures from access database. Can anyone help me?

Firstly, I will login to the system, secondly, after login to the system it will show the name, id and picture of the user. The name and id was complete, no problem, it runs well, but the picture failed to run.

Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
Bryan Lum
  • 19
  • 1
  • 1
  • 4
  • What is that section of comments and why is commented? That commented code has some chance to work, but your `ShowStaffData` has not. Check this - there is an example http://msdn.microsoft.com/cs-cz/library/system.windows.forms.picturebox.image%28v=vs.110%29.aspx – Vojtěch Dohnal Sep 19 '14 at 11:11
  • Possible duplicate http://stackoverflow.com/questions/10454595/loading-picturebox-image-from-database – Vojtěch Dohnal Sep 19 '14 at 11:17
  • And also VB.NET version here http://stackoverflow.com/questions/6350516/how-to-add-image-from-database-to-picturebox – Vojtěch Dohnal Sep 19 '14 at 11:19
  • Also check this http://stackoverflow.com/questions/217928/read-a-picture-from-access-db-into-picturebox – Vojtěch Dohnal Sep 19 '14 at 11:23
  • This will depend a lot on the version of MS Access and the field / column data type. – Fionnuala Sep 19 '14 at 11:30
  • MS Access stores pictures as OLE Objects, which contain wrappers. Here is a SO Answer that may help: http://stackoverflow.com/questions/17119798/loading-picture-stored-in-access-database-into-program-vb-net. – ron tornambe Sep 19 '14 at 14:05
  • @rontornambe Not necessarily, there is the Attachment data type, which is a little more complicated, and the more recent type for images etc. Prior to that, it was not a good idea to store anything but the path, or a blob. – Fionnuala Sep 20 '14 at 01:14

0 Answers0