Click here to Skip to main content

heinhtataung asked:

Open original thread
When the image exists at the database , It shows correctly at pictureBox.
If the image doesn't exist, it shows error.

The Code is Here !
 
  Private Sub gdCompany_CellClick_1(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles gdCompany.CellClick
        btnSave.Text = "ျပင္ရန္"
        picCompanyLogo.Visible = True
        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()
        Try
            'Get image data from gridview column. 
            Dim imageData As Byte() = DirectCast(gdCompany.CurrentRow.Cells(15).Value, Byte())
            'Initialize image variable 
            Dim newImage As Image
            'Read image data into a memory stream 
            Using ms As New MemoryStream(imageData, 0, imageData.Length)
                ms.Write(imageData, 0, imageData.Length)
                'Set image variable value using memory stream. 
                newImage = Image.FromStream(ms, True)
            End Using
            'set picture 
            picCompanyLogo.Image = newImage
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
            txtCompanyName.Focus()
        End Try
    End Sub
Tags: C#, VB.NET, Windows, .NET, WinForm

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid