Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
4.08/5 (3 votes)
See more:
Hi...
I am stored images into folder(images) and its path is stored in data base.
how can i display images in crystal reports using this path from database(~/images/img.jpg).
Thank u.
Posted
Updated 15-Jan-14 23:48pm
v3
Comments
[no name] 7-Jan-14 1:23am    
Pls see my code...

in .aspx:
<body>
<form id="form1" runat="server">
<div align="center">
<br />

<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" ToolPanelView="None" />

<br />
<xs:element name="image_stream" type="xs:base64Binary" minoccurs="0">
<br />

<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<report filename="CrystalReport.rpt">



</div>
</form>
</body>

in aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
string cs = "xxx";
MySqlConnection con; MySqlDataAdapter da;
MySqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
con = new MySqlConnection(cs);
cmd = new MySqlCommand("select image_path from patient_details WHERE FIRST_NAME='Murali'", con);
con.Open();
cmd.ExecuteNonQuery();
da = new MySqlDataAdapter(cmd);
DataTable dss = new DataTable();
DataSet ds = new DataSet();
da.Fill(ds);
string nn = ds.Tables[0].Rows.Count.ToString();
string path = ds.Tables[0].Rows[0]["IMAGE_PATH"].ToString();
con.Close();

AddImageColumn(ds.Tables[0], "image_stream");

for (int index=0; index < ds.Tables[0].Rows.Count; index++)
{
if (ds.Tables[0].Rows[index]["image_path"].ToString() != "")
{
if(File.Exists(this.Server.MapPath(ds.Tables[0].Rows[index]["image_path"].ToString())))
{
LoadImage(ds.Tables[0].Rows[index], "image_stream", ds.Tables[0].Rows[index]["image_path"].ToString());
}
else
{
LoadImage(ds.Tables[0].Rows[index], "image_stream", "~/No Image.jpg");
}
}
else
{
LoadImage(ds.Tables[0].Rows[index], "image_stream", "~/No Image.jpg");
}
}

ReportDocument crDoc = new ReportDocument();
crDoc.Load(Server.MapPath("CrystalReport.rpt"));
crDoc.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = crDoc;
}

private void AddImageColumn(System.Data.DataTable objDataTable, string strFieldName)
{
try
{
DataColumn objDataColumn = new DataColumn(strFieldName, Type.GetType("System.Byte[]"));
objDataTable.Columns.Add(objDataColumn);
}
catch (Exception ex)
{
Response.Write("" + ex.Message + "");
}
}

private void LoadImage(DataRow objDataRow, string strImageField, string FilePath)
{
try
{
FileStream fs = new FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] Image = new byte[fs.Length];
fs.Read(Image, 0, Convert.ToInt32(fs.Length));
fs.Close();
objDataRow[strImageField] = Image;
}
catch (Exception ex)
{
Response.Write(""+ex.Message+"");
}
}
}
its every thing is fine,but not show in crystal report. Pls help me.
Thank u.
[no name] 9-Jan-14 2:01am    
Is need any changes in crystal report or data set?
thank u.

 
Share this answer
 
Comments
[no name] 7-Jan-14 1:34am    
Pls see my above comment.
thank u
thatraja 7-Jan-14 1:59am    
Include comments in your question to see it clearly. You got any error?
Besides did you check my links in my answer?
[no name] 7-Jan-14 2:49am    
No error, but not shown image in crystal reports.
thank u.
thatraja 7-Jan-14 4:17am    
did you check my links in my answer?
[no name] 7-Jan-14 5:38am    
in your answered one,i tried. But it not show image in crystal report(using 1st link).
thank u.
Hi...
See this link for image saving, retrieving image and displaying image in crystal reports using Asp.net,MySQL.
How to store images and displaying images in crystal reports using asp.net,my sql[^]
Thank u.
 
Share this answer
 

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