user3496755
user3496755

Reputation: 19

I cant retrieve picture from access database

I would like to retrieve the picture from access database when the user login to the system. Firstly, the user will type his/her Staff ID and Password to login. Secondly, if the user granted to login the system, it will show another form. Thirdly, that another form will show the user's first name and last name. Furthermore, I would like to show the picture that saved in Access Database too. Could any senior help me?

This is my code:

Private Sub ShowStaffData(ByVal CurrentRow)
    txtFirstName.Text = DTS.Tables("Staff").Rows(CurrentRow)("User's_First_Name")
    txtLastName.Text = DTS.Tables("Staff").Rows(CurrentRow)("User's_Last_Name")
End Sub
Private Sub RetrieveStaffInformation()
    Dim StaffID As String
    Dim i, j As Integer
    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)
    txtStaff_ID.Text = Login.txtStaff_ID.Text
    Stream.Dispose()

    StaffID = txtStaff_ID.Text
    j = DTS.Tables("Staff").Rows.Count - 1
    i = 0
    While i <> j + 1
        If StaffID = DTS.Tables("Staff").Rows(i)("Staff_ID") Then
            ShowStaffData(i)
        End If
        i += 1
    End While
End Sub

Upvotes: 0

Views: 91

Answers (1)

Alin I
Alin I

Reputation: 590

Check you OleDbCommand. Maybe your select statement is not findind the Staff_ID because your where clause is comparing Staff_ID against a string, and in most cases this ID is a numeric value stored as integer.

Dim Command As New OleDbCommand("SELECT Picture FROM Staff WHERE Staff_ID = ?", Connection)
Command.Parameters.AddWithValue("@Staff_ID", CInt(txtStaff_ID.Text))

Anyway, you should provide some error details, if you got any errors...

Upvotes: 1

Related Questions