locked
Display picture in crystal report RRS feed

  • Question

  • User-343058236 posted

    I have 2 file. One named as "PrintPicReport.aspx" and the other is crystal report file named as "PicReport.rpt"

    This is my code to print data from database on crystal report in pdf form and save in "D drive"

    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 System.Data.Sql;              //  contains classes that support SQL Server-specific functionality
    using System.Data.SqlClient;        //  this namespace is the.NET Framework Data Provider for SQL Server
    using System.Data.SqlTypes;         //  provides classes for native data types in SQL Server
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    
    namespace CrystalReport
    {
        public partial class PrintPicReport : System.Web.UI.Page
        {
            public string GetConnectionString()
            {
                //sets the connection string from your web config file "ApplicationServices" is the name of your Connection String
                return System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            private void IdentityCard()
            {
                DataTable dt = new DataTable();
                using (SqlConnection conn = new SqlConnection(GetConnectionString()))
                {
                    string sql = "SELECT * FROM student_info AS si,student_pic AS sp WHERE si.num_admission = sp.num_admission AND si.num_admission = '" + TextBox1.Text + "'";
                    //string sql = "SELECT si.num_admission,si.name_full,si.gender,si.num_roll,si.stu_class,si.stu_section FROM student_info AS si,student_pic AS sp WHERE si.num_admission = sp.num_admission AND si.num_admission = '" + TextBox1.Text + "'";
    
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    SqlDataAdapter adt = new SqlDataAdapter(cmd);
    
                    cmd.Connection.Open();
                    adt.Fill(dt);
    
                    PicReport pr = new PicReport();
    
                    string mfiledate = DateTime.Now.ToShortDateString();
                    string mfiletime = DateTime.Now.ToShortTimeString();
                    string time1 = DateTime.Now.Hour.ToString() + "hr-" + DateTime.Now.Minute.ToString() + "min-" + DateTime.Now.Second.ToString() + "sec";
    
                    pr.SetDataSource(dt);
    
                    ExportOptions CrExportOptions;
                    DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                    PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                    CrDiskFileDestinationOptions.DiskFileName = "D:\\IdentityCard_" + mfiledate + "_" + time1 + ".pdf";
                    CrExportOptions = pr.ExportOptions;
                    {
                        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                        CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                        CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                        CrExportOptions.FormatOptions = CrFormatTypeOptions;
                    }
                    pr.Export();
    
                }
            }
    
            protected void View_Click(object sender, EventArgs e)
            {
                IdentityCard();
            }
        }
    }

    Now i want to display the image also. Image is saved in a folder let its path be "D:\image.jpg" 

    Now this path is saved in database.

    I have 2 tables first named as "student_info" having all data of student and second table named as "student_pic" having path of the image.

    Field name "num_admission" is used as foreign key in table "student_pic"

    Friday, September 13, 2013 8:39 AM

Answers

  • User-343058236 posted

    I used DataSet for printing pictures from folder whose path is saved in database on Crystal Report.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 7, 2013 8:53 AM