Results 1 to 7 of 7

Thread: {RESOLVED} Displaying Pictures From A File Path Stored In A Database

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    346

    Resolved {RESOLVED} Displaying Pictures From A File Path Stored In A Database

    Hey, I am using an ADO control to display records from my database and I want pictures to be shown to from a field in the same table, it has the pat hto the picture, I am using an image control to show them, when the form is loaded I am trying to get it too display the current record picture, here is my code

    VB Code:
    1. Private Sub Form_Load()
    2. browseConn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Documents and Settings\Rob\Desktop\VB\contacts.mdb"
    3.     browseConn.Open
    4.     browseRecc.Open "SELECT * from Contacts WHERE Name='" & lblName.Caption & "'", browseConn, adOpenDynamic, adLockOptimistic
    5.     imgAvatar.Picture = LoadPicture(" & browseRecc(" & avatar & ") & ")
    6. End Sub

    And then when I run it, it says 'File could not be found & browseRecc() &'
    can someone please help ?
    Last edited by robcarr2; Jun 3rd, 2005 at 02:27 PM.

    Microsoft gives you Windows, Linux gives you the whole house!


    I am who I am because of who we all are.


    We have just gotten a wake up call from the Nintendo generation.

  2. #2
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: Displaying Pictures From A File Path Stored In A Database

    Quote Originally Posted by robcarr2
    Hey, I am using an ADO control to display records from my database and I want pictures to be shown to from a field in the same table, it has the pat hto the picture, I am using an image control to show them, when the form is loaded I am trying to get it too display the current record picture, here is my code

    VB Code:
    1. Private Sub Form_Load()
    2. browseConn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Documents and Settings\Rob\Desktop\VB\contacts.mdb"
    3.     browseConn.Open
    4.     browseRecc.Open "SELECT * from Contacts WHERE Name='" & lblName.Caption & "'", browseConn, adOpenDynamic, adLockOptimistic
    5.     imgAvatar.Picture = LoadPicture(" & browseRecc(" & avatar & ") & ")
    6. End Sub

    And then when I run it, it says 'File could not be found & browseRecc() &'
    can someone please help ?
    Shouldn't
    VB Code:
    1. imgAvatar.Picture = LoadPicture(" & browseRecc(" & avatar & ") & ")
    be
    VB Code:
    1. imgAvatar.Picture = LoadPicture("" & browseRecc("" & avatar & "") & "")

    or something along those lines ?
    Zeegnahtuer?

  3. #3
    Addicted Member
    Join Date
    May 2005
    Posts
    168

    Re: Displaying Pictures From A File Path Stored In A Database

    Hi,

    'Assumes complete file path and filename are in the field: Avatar
    'like: C:\pictures\mypic.jpg

    imgAvatar.Picture = LoadPicture(browseRecc.fields("avatar"))

    OR

    'if picture files are in your application's folder you can use:
    imgAvatar.Picture = LoadPicture(App.Path & "\" & browseRecc.fields("avatar"))

    OR

    'Hardcoding the path.
    imgAvatar.Picture = LoadPicture("C:\" & browseRecc.fields("avatar"))

    Have a good one!
    BK

  4. #4
    Junior Member
    Join Date
    May 2005
    Location
    Litchfield, IL
    Posts
    22

    Re: Displaying Pictures From A File Path Stored In A Database

    Well, first off :

    1) Are you returning records for your SQL statement? How many?

    2) I do not see avatar declared or any value assigned to avatar for that matter? Maybe I am not reading your syntax right. Is avatar a string or a field?
    - ILJester

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    346

    Re: Displaying Pictures From A File Path Stored In A Database

    Quote Originally Posted by Black__Knight
    Hi,

    'Assumes complete file path and filename are in the field: Avatar
    'like: C:\pictures\mypic.jpg

    imgAvatar.Picture = LoadPicture(browseRecc.fields("avatar"))

    OR

    'if picture files are in your application's folder you can use:
    imgAvatar.Picture = LoadPicture(App.Path & "\" & browseRecc.fields("avatar"))

    OR

    'Hardcoding the path.
    imgAvatar.Picture = LoadPicture("C:\" & browseRecc.fields("avatar"))

    Have a good one!
    BK
    just tried
    VB Code:
    1. imgAvatar.Picture = LoadPicture(browseRecc.fields("avatar"))

    but it came up with an erorr saying Type Mismatch

    Microsoft gives you Windows, Linux gives you the whole house!


    I am who I am because of who we all are.


    We have just gotten a wake up call from the Nintendo generation.

  6. #6
    Addicted Member
    Join Date
    May 2005
    Posts
    168

    Re: Displaying Pictures From A File Path Stored In A Database

    Hi,

    Is your field: Avatar a text field? LIke JLester asked are you sure you are returning a record(s)?

    You can also try for testing purposes to remove the WHERE clause and return all records and see if the first picture is loaded. If not then the problem is with your WHERE clause and it isn't finding a matching record.

    'Place this line before your LoadPicture statement to make sure the path and filename are correct.

    Debug.Print browserecc.fields("Avatar")

    Have a good one!
    BK
    Last edited by Black__Knight; Jun 3rd, 2005 at 02:10 PM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    346

    Re: Displaying Pictures From A File Path Stored In A Database

    i have fixed it now, thanks for the code black knight

    Microsoft gives you Windows, Linux gives you the whole house!


    I am who I am because of who we all are.


    We have just gotten a wake up call from the Nintendo generation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width