0
votes

I am trying to display image in crystal report. In below code I convert image path in file stream then add in report source through data table. but still image not displayed

string path;
DataTable dt = new DataTable();

path = Server.MapPath("~/img/logo.jpg");   
DataColumn column = new DataColumn("Image"); //Create the column.
column.DataType = System.Type.GetType("System.Byte[]"); 
dt.Columns.Add(column);
DataRow row = dt.NewRow();
FileStream fs = new FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
Byte[] Image = new Byte[fs.Length];
fs.Read(Image, 0, Convert.ToInt32(fs.Length));
fs.Close();
row["Image"] = Image;
dt.Rows.Add(row);
dss.Tables[0].Merge(dt);
//set dataset to the report viewer.
rptDoc.SetDataSource(dss);
CrystalReportViewer1.ReportSource = rptDoc;
1

1 Answers

0
votes

You just have to save the Image in form of stream of bytes to database, you do not need to convert in back to use in crystal reports, just call the field name with the image by dragging and dropping it onto the report field, the image will display.. I used to do it in C#. Hope it works for you too.