Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load images in picturebox

Status
Not open for further replies.

brews

Technical User
Dec 12, 2007
194
0
0
US
Using OpenFileDialog, a picture is loaded into a picbox and then saved to a db using only the picName not the path. When the record is subsequently called by these procedures an error message says that the pic could not be found and gives the path which is exactly where the pic is stored. The code and notes:
Code:
            If dataMgr.FindPix(intID, sImageFile) Then
                nMember.ClassPhoto = Replace(nMember.ClassPhoto, "''", "'")
                .imgClassPhoto.Load(nMember.ClassPhoto) [COLOR=red]'error msg about path[/color red]
                .btnChangePhoto.Text = "&Change Pho&to"
                btnChangePhoto.Font = New Font("arial", 8)
            Else
                .btnChangePhoto.Text = "Add Pho&to"
                btnChangePhoto.Font = New Font("arial", 8)
                .imgClassPhoto.Image = Nothing [COLOR=red]'is this the code for having a blank picbox if no pic is in the db?[/color red]
            End If

    Public Function FindPix(ByVal iID As Integer, ByRef sFile As String) As Boolean
        Dim dr As DataRow
        da = New OleDbDataAdapter
        ds = New DataSet
        da = New OleDbDataAdapter
        If cn.State = ConnectionState.Closed Then cn.Open()
        cmd = New OleDbCommand("SELECT MemberID, ClassPhoto FROM Members WHERE ClassPhoto ='" & sFile & "'", cn)
        da.SelectCommand = cmd
        da.Fill(ds, "Members")
        Try
            For Each dr In ds.Tables("Members").Rows
                With nMem
                    If .ClassPhoto = "" Then
                        cn.Close()
                        Return False
                    Else
                        sFile = .ClassPhoto
                    End If
                End With
                cn.Close()
                Return True
            Next dr
            cn.Close()
        Catch ex As Exception

        End Try
    End Function

Thank you.
 
The code was changed to this and now it works:
Code:
                sPath = Application.StartupPath & "\Photos"
                .imgClassPhoto.Load(sPath & "\" & nMember.ClassPhoto)

Thanks for the consideration. Any comments are always welcome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top