Dynamically Loading Image in Crystal Report
-
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..!