Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How can i retrieve image to pictureBox ?

How can i retrieve image to pictureBox ?

Scheduled Pinned Locked Moved Visual Basic
questioncsharpjavadatabase
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    heinhtataung
    wrote on last edited by
    #1

    I'm using Stored Procedure,3 tier and VB.net. :) Now, i click the gridview and then want to show the data in textboxes and pictureBox to update the informations. :rolleyes: :java: The problem is that , how can i retrieve photo to picture box???:confused: X| :doh: :mad: :(( Here is my code :|

    Private Sub gdCompany_CellClick(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles gdCompany.CellClick
    btnSave.Text = "ျပင္ရန္"
    txtCompanyName.Text = gdCompany.CurrentRow.Cells(1).Value.ToString()
    txtDescription.Text = gdCompany.CurrentRow.Cells(2).Value.ToString()
    txtPhoneNo.Text = gdCompany.CurrentRow.Cells(3).Value.ToString()
    txtFaxNo.Text = gdCompany.CurrentRow.Cells(4).Value.ToString()
    txtEmail.Text = gdCompany.CurrentRow.Cells(5).Value.ToString()
    txtWebsite.Text = gdCompany.CurrentRow.Cells(6).Value.ToString()
    ddlBankName.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(7).Value.ToString())
    ddlBankBranch.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(8).Value.ToString())
    txtBankAccountNo.Text = gdCompany.CurrentRow.Cells(9).Value.ToString()
    txtAddress.Text = gdCompany.CurrentRow.Cells(10).Value.ToString()

        'picCompanyLogo.Image = Convert.ToByte(gdCompany.CurrentRow.Cells(15).Value.ToString())
       
    
      
        txtCompanyName.Focus()
    End Sub
    
    L S 2 Replies Last reply
    0
    • H heinhtataung

      I'm using Stored Procedure,3 tier and VB.net. :) Now, i click the gridview and then want to show the data in textboxes and pictureBox to update the informations. :rolleyes: :java: The problem is that , how can i retrieve photo to picture box???:confused: X| :doh: :mad: :(( Here is my code :|

      Private Sub gdCompany_CellClick(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles gdCompany.CellClick
      btnSave.Text = "ျပင္ရန္"
      txtCompanyName.Text = gdCompany.CurrentRow.Cells(1).Value.ToString()
      txtDescription.Text = gdCompany.CurrentRow.Cells(2).Value.ToString()
      txtPhoneNo.Text = gdCompany.CurrentRow.Cells(3).Value.ToString()
      txtFaxNo.Text = gdCompany.CurrentRow.Cells(4).Value.ToString()
      txtEmail.Text = gdCompany.CurrentRow.Cells(5).Value.ToString()
      txtWebsite.Text = gdCompany.CurrentRow.Cells(6).Value.ToString()
      ddlBankName.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(7).Value.ToString())
      ddlBankBranch.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(8).Value.ToString())
      txtBankAccountNo.Text = gdCompany.CurrentRow.Cells(9).Value.ToString()
      txtAddress.Text = gdCompany.CurrentRow.Cells(10).Value.ToString()

          'picCompanyLogo.Image = Convert.ToByte(gdCompany.CurrentRow.Cells(15).Value.ToString())
         
      
        
          txtCompanyName.Focus()
      End Sub
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'd recommend creating a "new application" to try implement this technique; that way you won't be bothered with code that has little to do with this particular problem. You already have the bytes; you can put those in a memorystream[^] and load your image from that stream[^].

      Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

      1 Reply Last reply
      0
      • H heinhtataung

        I'm using Stored Procedure,3 tier and VB.net. :) Now, i click the gridview and then want to show the data in textboxes and pictureBox to update the informations. :rolleyes: :java: The problem is that , how can i retrieve photo to picture box???:confused: X| :doh: :mad: :(( Here is my code :|

        Private Sub gdCompany_CellClick(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles gdCompany.CellClick
        btnSave.Text = "ျပင္ရန္"
        txtCompanyName.Text = gdCompany.CurrentRow.Cells(1).Value.ToString()
        txtDescription.Text = gdCompany.CurrentRow.Cells(2).Value.ToString()
        txtPhoneNo.Text = gdCompany.CurrentRow.Cells(3).Value.ToString()
        txtFaxNo.Text = gdCompany.CurrentRow.Cells(4).Value.ToString()
        txtEmail.Text = gdCompany.CurrentRow.Cells(5).Value.ToString()
        txtWebsite.Text = gdCompany.CurrentRow.Cells(6).Value.ToString()
        ddlBankName.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(7).Value.ToString())
        ddlBankBranch.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(8).Value.ToString())
        txtBankAccountNo.Text = gdCompany.CurrentRow.Cells(9).Value.ToString()
        txtAddress.Text = gdCompany.CurrentRow.Cells(10).Value.ToString()

            'picCompanyLogo.Image = Convert.ToByte(gdCompany.CurrentRow.Cells(15).Value.ToString())
           
        
          
            txtCompanyName.Focus()
        End Sub
        
        S Offline
        S Offline
        SZLMCL
        wrote on last edited by
        #3

        hy This function converts byte array to image:

        Public Shared Function ByteArrayToImage(ByVal ByteArr() As Byte) As Object
        Dim ImageStream As System.IO.MemoryStream

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

        and this convert back:

        Public Shared Function ImageToByteArray(ByVal NewImage As Image) As Object
        Dim ImageStream As System.IO.MemoryStream
        Dim ByteArr() As Byte

                    Try
                        ReDim ByteArr(0)
                        If NewImage IsNot Nothing Then
                            ImageStream = New System.IO.MemoryStream
                            NewImage.Save(ImageStream, Imaging.ImageFormat.Jpeg)
                            ReDim ByteArr(CInt(ImageStream.Length - 1))
                            ImageStream.Position = 0
                            ImageStream.Read(ByteArr, 0, CInt(ImageStream.Length))
                        End If
                        Return ByteArr
                    Catch ex As Exception
                        Return Nothing
                    End Try
                End Function
        

        +You need DBNull check when the column allow nulls.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups