Thursday, March 21, 2013

Use Crystal Report in C#

Code to view the Crystal Report using C#.

Namespace:

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;


Code:


            CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
             CrystalDecisions.Shared.IConnectionInfo conn;


             ConnectionInfo CInfo = new ConnectionInfo();
             CInfo.ServerName = "server";
             CInfo.UserID = "ID";
             CInfo.Password = "Password";

             TableLogOnInfo tableInfo = new TableLogOnInfo();
             tableInfo.ConnectionInfo = CInfo;

             TableLogOnInfos tablelog = new TableLogOnInfos();
             tablelog.Add(tableInfo);

             crystalReportViewer1.ReportSource = Application.StartupPath + "\\Report.rpt";
             crystalReportViewer1.LogOnInfo = tablelog;

             ReportDocument obj = new ReportDocument();
             obj.Load(Application.StartupPath + "\\Report.rpt");

              obj.SetParameterValue("Para1","Value");
             obj.SetParameterValue("Para2", "Value");
           
             crystalReportViewer1.ReportSource = obj;

No comments:

Post a Comment