views:

22

answers:

1

I am trying to display image from dataset xsd on crystal report, but it is not displaying image. Please help me.

Regards Riyaz

    string sql = "select * from ImageUpload";
    SqlDataAdapter da = new SqlDataAdapter(sql, strConn);
    DataSet ds = new DataSet();
    da.Fill(ds, "Image");       

    for (int index = 0; index < ds.Tables[0].Rows.Count; index++)
    {
        if (ds.Tables[0].Rows[index]["thumb_path"].ToString() != "")
        {
            //if (File.Exists(Server.MapPath("~/129204153594EFF/Image13.jpg") +
            //    ds.Tables[0].Rows[index]["thumb_path"].ToString()))

            if (File.Exists(Server.MapPath("~/129204153594EFF/Image13.jpg")))
            {
                LoadImage(ds.Tables[0].Rows[index], "image_stream",
                    Server.MapPath("~/129204153594EFF/Image13.jpg"));
            }
        }
    }

    // ReportDocument crReportDocument = BLL.BusinessLogicLayer.Globals.GetReportDocument("rport.rpt");

    ReportDocument crReportDocument = BLL.BusinessLogicLayer.Globals.GetReportDocument("rport.rpt");

    crReportDocument.SetDataSource(ds.Tables[0]);
    CrystalReportViewer1.ReportSource = crReportDocument;   
}

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)
    {
        //Handler
    }
}
A: 

add this with the appropriate token and version for crystal reports and you will be good to go to your web.config file

Nishant