Click here to Skip to main content
15,891,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am passing images from my local disk to crystal reports using VB.net code. I have completed passing one image from my local drive to crystal reports, but the issue is I want to pass many images from the same drive. I am using the code below for passing the images:

VB
' object of data row
     Dim drow As DataRow
     ' add the column in table to store the image of Byte array type
     dt.Columns.Add("Image", System.Type.GetType("System.Byte[]"))
     drow = dt.NewRow
     ' define the filestream object to read the image
     Dim fs As FileStream
     ' define te binary reader to read the bytes of image
     Dim br As BinaryReader
     ' check the existance of image
     If File.Exists(AppDomain.CurrentDomain.BaseDirectory & "10157.Jpg") Then
         ' open image in file stream
         fs = New FileStream(AppDomain.CurrentDomain.BaseDirectory & "10157.Jpg", FileMode.Open)
     Else ' if phot does not exist show the nophoto.jpg file
         fs = New FileStream(AppDomain.CurrentDomain.BaseDirectory & "FLYWELL.jpg", FileMode.Open)
     End If
     ' initialise the binary reader from file streamobject
     br = New BinaryReader(fs)
     ' define the byte array of filelength
     Dim imgbyte(fs.Length) As Byte
     ' read the bytes from the binary reader
     imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)))
     drow(0) = imgbyte       ' add the image in bytearray
     dt.Rows.Add(drow)       ' add row into the datatable
     br.Close()              ' close the binary reader
     fs.Close()              ' close the file stream
     Dim rptobj As New CrystalReport1    ' object of crystal report
     rptobj.SetDataSource(dt)
     CrystalReportViewer1.ReportSource = rptobj  'set the report source
Posted
Updated 29-Jun-21 16:27pm
v3
Comments
Manfred Rudolf Bihy 30-Mar-11 8:03am    
Edit: Added code tags, spelling and grammar, sensible title added
Kschuler 30-Mar-11 11:48am    
You asked this exact same question 2 days ago:
http://www.codeproject.com/Questions/173659/images-in-crystal-report.aspx
What work have you done on it since?

1 solution

 
Share this answer
 
Comments
sameertm 30-Mar-11 9:20am    
Dear Sandeep in my question i have mentioned some coding that coding itself i can pass images, but the problem is i can pass only one image i want to pass many images
Sandeep Mewara 30-Mar-11 9:31am    
So, add them to a datatable row-wise ans then refer the datatable to crystal report.
sameertm 30-Mar-11 9:41am    
can u tell me how to add data table
Sandeep Mewara 30-Mar-11 9:46am    
You can add datatable as a datasource to reports. Right?
sameertm 30-Mar-11 9:48am    
can u give some sample coding for create datatable

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900