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. Loading image dynamically in crystal report

Loading image dynamically in crystal report

Scheduled Pinned Locked Moved Visual Basic
helpdatabasedebuggingannouncement
2 Posts 2 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.
  • O Offline
    O Offline
    Ovais Memon
    wrote on last edited by
    #1

    I have a field of Image path on database and I need to display the image of student in crystal report. I am using VS2005 with crystal report version 9. I have added the unbound column named "Image" of type system.byte in Data Set and at the load event, I have write the following code. Dim da As New DataSet1TableAdapters.AdmissionFormTableAdapter Dim dt As New DataSet1.AdmissionFormDataTable da.FillByStudentID(dt, _studentID) Dim dtCopy As New DataTable ''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Code Start to Set Image ''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim blankFile As String = "C:\Program Files\blank.JPG" If dt.Rows(0).Item("ImagePath").ToString <> "" Then Dim s As String = dt.Rows(0).Item("ImagePath").ToString If FileIO.FileSystem.FileExists(s) Then Dim fs As FileStream = New FileStream(s, FileMode.Open, FileAccess.Read) Dim image(fs.Length) As Byte fs.Read(image, 0, Convert.ToInt32(fs.Length)) dt.Rows(0).Item("Image") = image fs.Close() Else Dim fs As FileStream = New FileStream(blankFile, FileMode.Open, FileAccess.Read) Dim image(fs.Length) As Byte fs.Read(image, 0, Convert.ToInt32(fs.Length)) dt.Rows(0).Item("Image") = image fs.Close() End If Else Dim fs As FileStream = New FileStream(blankFile, FileMode.Open, FileAccess.Read) Dim image(fs.Length) As Byte fs.Read(image, 0, Convert.ToInt32(fs.Length)) dt.Rows(0).Item("Image") = image fs.Close() End If ''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Code End to Set Image ''''''''''''''''''''''''''''''''''''''''''''''''''''''' dtCopy = dt.Copy Me.rptAdmissionForm1.SetDataSource(dtCopy) Me.rptAdmissionForm1.SetParameterValue("ID", _studentID) When I run the code, error comes that "unable to cast type of system.byte to system.IConvertible", although the datatype of column "Image" is system.byte, and when I debug the code, it shows the datatype of dt.Rows(0).Item("Image") = System.DBNull, Please help me out..!

    K 1 Reply Last reply
    0
    • O Ovais Memon

      I have a field of Image path on database and I need to display the image of student in crystal report. I am using VS2005 with crystal report version 9. I have added the unbound column named "Image" of type system.byte in Data Set and at the load event, I have write the following code. Dim da As New DataSet1TableAdapters.AdmissionFormTableAdapter Dim dt As New DataSet1.AdmissionFormDataTable da.FillByStudentID(dt, _studentID) Dim dtCopy As New DataTable ''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Code Start to Set Image ''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim blankFile As String = "C:\Program Files\blank.JPG" If dt.Rows(0).Item("ImagePath").ToString <> "" Then Dim s As String = dt.Rows(0).Item("ImagePath").ToString If FileIO.FileSystem.FileExists(s) Then Dim fs As FileStream = New FileStream(s, FileMode.Open, FileAccess.Read) Dim image(fs.Length) As Byte fs.Read(image, 0, Convert.ToInt32(fs.Length)) dt.Rows(0).Item("Image") = image fs.Close() Else Dim fs As FileStream = New FileStream(blankFile, FileMode.Open, FileAccess.Read) Dim image(fs.Length) As Byte fs.Read(image, 0, Convert.ToInt32(fs.Length)) dt.Rows(0).Item("Image") = image fs.Close() End If Else Dim fs As FileStream = New FileStream(blankFile, FileMode.Open, FileAccess.Read) Dim image(fs.Length) As Byte fs.Read(image, 0, Convert.ToInt32(fs.Length)) dt.Rows(0).Item("Image") = image fs.Close() End If ''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Code End to Set Image ''''''''''''''''''''''''''''''''''''''''''''''''''''''' dtCopy = dt.Copy Me.rptAdmissionForm1.SetDataSource(dtCopy) Me.rptAdmissionForm1.SetParameterValue("ID", _studentID) When I run the code, error comes that "unable to cast type of system.byte to system.IConvertible", although the datatype of column "Image" is system.byte, and when I debug the code, it shows the datatype of dt.Rows(0).Item("Image") = System.DBNull, Please help me out..!

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      Your code is very confusing as you have variables named the same but at different levels. It would be easier to find the problem if you would have just one main variable for the filestream, one for the image byte array. Use if statements to determine which file you want to load, then when you've done all the checks you can have just one spot that actually uses the filestream reader code. You might also want to try using this instead of your filestreamreader code to convert the file into a byte array: If FileIO.FileSystem.FileExists(s) Then System.IO.File.ReadAllBytes(s) End If Also, is there a reason you make a copy of the datatable to send in, instead of just sending dt? Hope this helps.

      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