Click here to Skip to main content
15,921,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends,

how to get the image by imagepath from db ,should view in crystalreportviewer.
here i did but image is not displaying.

C#
public void load_report()
   {
       DataSet1 ds = new DataSet1();
       DataTable dt_patientdetails = new DataTable();
       dt_patientdetails = objdbaccess.getdata1("select PATIENT_ID,FIRST_NAME,FATHER_NAME,DATE_OF_BIRTH,AGE,BLOOD_GROUP,SEX,MARITAL_STATUS,PATIENT_MOBILE_NUMBER,PATIENT_EMAIL_ID,PATIENT_ATTENDER_NAME,PATIENT_ATTENDER_CONTACT_NUMBER,PATIENT_ADDRESS_LINE1,PATIENT_ADDRESS_LINE2,PATIENT_ADDRESS_CITY,PATIENT_ADDRESS_STATE,PATIENT_ADDRESS_COUNTRY,PATIENT_ATTENDER_ADDRESS_LINE1,PATIENT_ATTENDER_ADDRESS_LINE2,PATIENT_ATTENDER_ADDRESS_CITY,PATIENT_ATTENDER_ADDRESS_STATE,ALLERGY_DETAIL,REFERRED_BY_DOCTOR,IMAGE_PATH from patient_details where PATIENT_ID='" + HiddenField1.Value + "'");
       ds.Tables["DataTable5"].Merge(dt_patientdetails, false);
       ReportDocument report = new ReportDocument();
       report.Load(Server.MapPath("/CMS-01082011-old/CrystalReports/Admit Card.rpt"));
       report.SetDataSource(ds);
       CrystalReportViewer1.ReportSource = report;
       CrystalReportViewer1.RefreshReport();
       CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
   }


please help me out
thanking you
Posted

            DataTable dt = //getdatatabel from database

            if (dt.Rows.Count > 0)
            {
                dt.Columns.Add("photo", typeof(System.Byte[]));

                foreach (DataRow row in dt.Rows)
                {
                    string path = get photo path where photo save;

                   
                    if (path != "0")
                    {
                        //for resizeing image/////////////////////////////////////////
                        int imageHeight = 200;
                        int imageWidth = 150;
                        //path = path.Replace("C:", "E:");

                        System.Drawing.Image fullSizeImg
                                = System.Drawing.Image.FromFile(path);

                        System.Drawing.Image.GetThumbnailImageAbort dummyCallBack
                                = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

                        System.Drawing.Image thumbNailImg
                                = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight,
                        dummyCallBack, IntPtr.Zero);

                        MemoryStream ms = new MemoryStream();
                        string s = path.Substring(path.LastIndexOf('.') + 1, 3).ToLower();
                        if (s == "jpg")
                        {
                            thumbNailImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                        else
                        {
                            thumbNailImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);//needs change,it is not displaying image for .gif.
                        }

                        row["photo"] = ms.ToArray();
                        //fs.Close();
                        ms.Close();
                        //br.Close();
                        thumbNailImg.Dispose();
                    }
                }


                CrystalReportSource1.Report.FileName = Server.MapPath("/Report/AdmitCard.rpt");
                CrystalReportSource1.ReportDocument.SetDataSource(dt);
                fsApplication.Visible = true;
                CrystalReportSource1.DataBind();
                CrystalReportViewer1.Visible = true;
                //DivRpt.Visible = true;
         



use photo field in Schema
 <xs:element name="photo" type="xs:base64Binary" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
 
Share this answer
 
Comments
Mr.VJ 4-Jan-14 6:59am    
hello virandra , here i getting an error
System.Drawing.Image fullSizeImg
= System.Drawing.Image.FromFile(path);

path cannot found but everything was ok.
 
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