Results 1 to 3 of 3

Thread: Trying to get Image from Access OLE Object into PictureBox in VB code

Hybrid View

  1. #1
    New Member
    Join Date
    May 12
    Posts
    2

    Trying to get Image from Access OLE Object into PictureBox in VB code

    I am programming with Access 2007
    VB.net in Visual Studio 2010

    I am trying to have my VB program read the database, extract the .bmp image, and assign it to a PictureBox on the fly (I am actually creating a Group on the fly and filling it with data from the database that are selected by my query. One of the fields is "image". All of my other fields are successfully transferring from the DB to the group box.) My problem is converting the OLE Object to a picture/image that I can assign to the PictureBox.

    I am using TableAdapters and queries set up in an .xsd.

    I have a database with an OLE Object field.

    Here is a code snipit of my database set up:

    Dim ta AsNew dsWhiteboardTableAdapters.MonstersTableAdapter
    Dim monsterList AsNewdsWhiteboard.MonstersDataTable
    Dim monster AsdsWhiteboard.MonstersRow
    Dim newMonster AsGroupBox

    ta.Fill(monsterList)

    Dim cnt AsInteger = monsterList.Rows.Count

    If cnt > 0 Then

    For r AsInteger = 0 To cnt - 1
    monster = CType(monsterList.Rows(r), dsWhiteboard.MonstersRow)
    newMonster = NewGroupBox

    newMonster.Text = monster.condition
    newMonster.Tag = monster.ID
    newMonster.Size = NewSize(grpWidth, grpHeight)
    newMonster.Location = NewPoint(xCoord, yCoord(grpCounter))
    newMonster.BackColor = Color.FromKnownColor(KnownColor.Control)
    'newCharacter.Font = New Font("Microsoft Sans Serif", 8)
    newMonster.Font = NewFont("Microsoft Sans Serif", 12, FontStyle.Bold)
    newMonster.ForeColor = Color.DarkRed

    'Add Image to group for Pic
    newPic = NewPictureBox
    newPic.Location = NewPoint(72, 5)
    newPic.Size = NewSize(54, 54)
    Participants.Add(newMonster)
    grpCounter += 1
    Next


    I have tried several ways of getting the image into my picturebox, all lead to errors. I also searched forums for solutions and none seemed to work in my scenario.

    If you need additional code, i would be glad to provide.
    Any suggestions?

  2. #2
    .Net Member dday9's Avatar
    Join Date
    Mar 11
    Location
    South Louisiana
    Posts
    2,325

    Re: Trying to get Image from Access OLE Object into PictureBox in VB code

    Take a look at JMc's codebank thread here.
    Vb.Net Contributions:-Here-
    Game Contributions:-Here- New - 2d map creator
    XNA in Vb.Net Tutorials:-Here-

    Links:
    LegalShield | AUP

  3. #3
    New Member
    Join Date
    May 12
    Posts
    2

    Re: Trying to get Image from Access OLE Object into PictureBox in VB code

    Here is his code example:
    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()

    I tried, but where i get confused is with "command". please look at my code sample with TableAdapters. How do I convert my tableAdapter usage to this code sample?

Posting Permissions

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