Image not loading in Crystal Report
-
Dear All, I have some problem in loading an image in crystal report. I am using VS 2005 with CR 9. I have a table adapter in which i used an unbound column "Image" of type System.Byte. And I used the following code to set image. .... Dim s As String = dt.Rows(0).Item("ImagePath").ToString 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 ................................(1) fs.Close() .... But it throws an exception at (1) [Unable to cast type of System.IConvertible to type System.Byte] I used to debug the code, and when i reached at (1), i found the datatype of dt.Rows(0).item("Image") = System.DBNull Although it is set to type System.Byte at design time in Table Adapter. Please help me out Regards, Ovais
-
Dear All, I have some problem in loading an image in crystal report. I am using VS 2005 with CR 9. I have a table adapter in which i used an unbound column "Image" of type System.Byte. And I used the following code to set image. .... Dim s As String = dt.Rows(0).Item("ImagePath").ToString 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 ................................(1) fs.Close() .... But it throws an exception at (1) [Unable to cast type of System.IConvertible to type System.Byte] I used to debug the code, and when i reached at (1), i found the datatype of dt.Rows(0).item("Image") = System.DBNull Although it is set to type System.Byte at design time in Table Adapter. Please help me out Regards, Ovais
I haven't used a Table Adapter like you are talking about, but one thought that came to me when reading this is that a System.Byte is not the same data type as your image variable. You need a Byte array. This code:
Dim image(fs.Length) As Byte
declares a Byte array, not a Byte. Hope this helps.