Hi alls,

since 2 week i'm stuck to do this thing. Actually i need to display image from oracle database into the picturebox. My oracle database got table name "STAFF_PHOTO" and the column of photo is "PICTURE". The image already converted into ByteArray.

I'm already make a connection and success but the image stil cannot display. already refer to the tutorial but still stuck. I'm also try to use Memorystream but still can't.. anybody can help me plz....:(

Here's my old blog post, how to do conversions between byte arrays and image type: Convert image to byte array and vice versa. And here's how you get the image to the picture box: Byte2Image(PictureBox1.Image, ByteArr) where the ByteArr parameter contains the data from your database.

thanks for reply, can u guide me to do it?....where to put the the coding :- Below ButtonClick or where?...thank you...hope u can help me..

I suggest to Copy/Paste the routine as it is i.e. as a separate procedure. Then load an array of bytes from db in button click event and call the routine to test it (i.e. you do get the image in the picture box).

If everything works fine, "extend" those methods to be a part of your main application.

I;m so sorry sir, i'm really dumb....
I'm already try to do with ur suggestgiion but still hang,

Ps answer my stupid question ,eekekeke"

1.The coding that ur given should been paste in "new Module.vb"?
2.Did i have to convert my bytearray image data into filestream first?
3.Can u guide me with little example sir....so help pls....i'm drowning...


tq

Here you go. Create a new form and drop a picturebox control and one button control to it. This is sample code, fix naming if needed, add error handling and add the code for getting data out of Oracle:

Option Strict On
Option Explicit On

Imports System.IO

Public Class Form1

  Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    '

  End Sub

  ''' <summary>
  ''' Convert a byte array to an Image
  ''' </summary>
  ''' <param name="NewImage">Image to be returned</param>
  ''' <param name="ByteArr">Contains bytes to be converted</param>
  ''' <remarks></remarks>
  Public Sub Byte2Image(ByRef NewImage As Image, ByVal ByteArr() As Byte)
    '
    Dim ImageStream As MemoryStream

    Try
      If ByteArr.GetUpperBound(0) > 0 Then
        ImageStream = New MemoryStream(ByteArr)
        NewImage = Image.FromStream(ImageStream)
      Else
        NewImage = Nothing
      End If
    Catch ex As Exception
      NewImage = Nothing
    End Try

  End Sub

  Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    '
    Dim BytesFromDB() As Byte
    Dim TempImage As Image ' Temp image just to help debugging

    TempImage = Nothing
    ReDim BytesFromDB(0) ' "Empty" array
    ' Open connection to Oracle DB
    ' Get the image(bytes) from Oracle DB to BytesFromDB() array

    ' Convert bytes to image
    Byte2Image(TempImage, BytesFromDB)
    ' Check if conversion was ok
    If TempImage IsNot Nothing Then
      PictureBox1.Image = TempImage
    Else
      MessageBox.Show("Cannot convert to image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    End If

  End Sub

End Class

Thank you sir, i'm trying but blank "

' Open connection to Oracle DB
        Dim cn As New OracleConnection("Data Source=172.16.30.19/kuktemdb;User Id=asis;Password=asis;")
        ' Get the image(bytes) from Oracle DB to BytesFromDB() array
        Try 'create command object 
            Dim sb As New System.Text.StringBuilder
            Dim da As OracleDataAdapter
            'Dim cmd As OracleCommand
            sb.Append(" Select * From STAFF_PHOTO where SP_STAFF_ID LIKE '" & TextBox1.Text & "'")
            'sb.Append("select * FROM PICTURE_TABLE WHERE ID LIKE '" & TextBox1.Text & "'")
            'sb.Append(" WHERE ID = " & Me.TextBox1.Text)
            Dim cmd As New OracleCommand(sb.ToString, cn)




            ' cmd()

            cn.Open()
            Dim rdr As OracleDataReader = cmd.ExecuteReader

            If rdr.Read() Then
                Picturebox1.image = image.......
            End If

what worng sir with my coding?

Pls help me......plzzzzz

Thanx, very usefull, clean and quick

Thank you, aggain!

dgdgdgdg

This code is such a great help, but I just picked up the part that I needed.

Thank you very much!


-Jeff Balbalosa
Pinoy!

hello Plz Help me.............
I am gettin error "Parameter is not valid" at dis line ...........

NewImage = Image.FromStream(ImageStream)

how to solve

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.