Wednesday, August 4, 2010

Crystal Report in asp.net

To create crystal report in asp.net follow below steps
1. take a crystal report viewer on page (i have given name "crv" to it)
then write below code in code behind file.

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

private void showreport()
{
ReportDocument report = new ReportDocument();
report.Load(Server.MapPath("MyReportName.rpt"));
report.SetDataSource(objrep.ReportDataSource);
SetTableLocation(report.Database.Tables);
crv.ReportSource = report; //crv is your Crystal report viewer's name.
}


private void SetTableLocation(Tables tables)
{
ConnectionInfo connectionInfo = new ConnectionInfo();

connectionInfo.ServerName = @"DBSERVER2\SQL2005";
connectionInfo.DatabaseName = "dbMEAVer5web";
connectionInfo.UserID = "sa";
connectionInfo.Password = "admin55";

foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogOnInfo);
}
}



Solution by: Rajesh Rolen

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates