locked
How to generate crystal report throw code (not dynamically) RRS feed

  • Question

  • User1594475756 posted

    hi, all

    Iam created crystal report dynamically but i want that throw code only generate report i dont want that to field explorer in crystal report

    i wrote code like this it is working when i interact with fiel explorer and drag& drop the fileds

    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=education;Integrated Security=True");
        protected void Page_Load(object sender, EventArgs e)
        {
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from studentinfo", con);
            DataSet d = new DataSet();
            da.Fill(d);
            ReportDocument r = new ReportDocument();
            r.Load(Server.MapPath("~/CrystalReport.rpt"));
            r.SetDataSource(d);
            CrystalReportViewer1.ReportSource = r;

            CrystalReportViewer1.DataBind();
            con.Close();

    }

    can any one help me

    Tuesday, September 13, 2011 2:43 AM

All replies

  • User1283497924 posted

    Hi,

    Please check the below code:

    using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using CrystalDecisions.CrystalReports.Engine;

    using CrystalDecisions.Shared;

    public partial class OfficeWiseReportType3 : System.Web.UI.Page

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    ParameterFields parameterFields = CrystalReportViewer1.ParameterFieldInfo;
     
    //Provide server information to crystal report

    CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = "<Server IP>";

    CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = "<User ID>";

    CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = "<Password>";
    CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = "<Data base name>";

    ReportDocument report = new ReportDocument();

    //Map The report .rpt file

    report.Load(Server.MapPath("crystalReport.rpt"));

    //Pass parameter to stored procedure

    ParameterValues currentParameterValues = new ParameterValues();

    ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();

    parameterDiscreteValue.Value = <Value to pass>;

    currentParameterValues.Add(parameterDiscreteValue);

    ParameterField parameterField = parameterFields[0];

    parameterField.CurrentValues = currentParameterValues;

    report.Close();

    report.Dispose();

    }

    }
    For more detailcheck the link
    http://www.dotnethunter.com/ArticleDetail.aspx?ArticleId=166&category=23&ArticleTitle=How%20to%20pass%20parameter%20to%20a%20crystal%20report%20using%20c#
    Friday, September 30, 2011 12:03 PM