I know that this has been a problem that has been posted all over the web. I have read all the posts and still can't resolve my problem. I am running VS.NET 2003. My problem is when I try to bring in a crystal report that already exists into my web application. It is created using CR 8.5. I have tried creating a report in VS.NET using its version of Crystal Reports and it works fine using the EXACT same code that I have below that doesn't work for the existing report. Parameters and tables/views are the same for both reports.
Here is the code that I have:
I appreciate any help that you can give.
Here is the code that I have:
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace LMDashboard
{
/// <summary>
/// Summary description for TMXWeeklyReport.
/// </summary>
public class TMXWeeklyReport : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
string strStartDate, strEndDate;
TMXDetailCompanywide crReportDocument = new TMXDetailCompanywide();
Database crDatabase;
Tables crTables;
//CrystalDecisions.CrystalReports.Engine.Table crTable;
TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
//crReportDocument ;
private void Page_Load(object sender, System.EventArgs e)
{
strStartDate = Request.QueryString.Get("StartDate");
strEndDate = Request.QueryString.Get("EndDate");
crConnectionInfo.ServerName = "server";
crConnectionInfo.DatabaseName = "db";
crConnectionInfo.UserID = "user";
crConnectionInfo.Password = "password";
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;
//Apply the logon information to each table in the collection
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}
//Once the connection to the database has been established for
//each table in the report, the report object can be bound to the viewer
//using the reportsource property of the viewer to display the report.
CrystalReportViewer1.ReportSource = crReportDocument;
setReportParameters();
//CrystalReportViewer1.DataBind();
}
private void setReportParameters()
{
ParameterFields paramFields = new ParameterFields();
ParameterField pfStartDate = new ParameterField();
ParameterField pfEndDate = new ParameterField();
pfStartDate.ParameterFieldName = "StartDate";
pfEndDate.ParameterFieldName = "End Date";
ParameterDiscreteValue dcStartDate = new ParameterDiscreteValue();
ParameterDiscreteValue dcEndDate = new ParameterDiscreteValue();
//dcStartDate.Value = DateTime.Parse(strStartDate);
//dcEndDate.Value = DateTime.Parse(strEndDate);
dcStartDate.Value = strStartDate;
dcEndDate.Value = strEndDate;
pfStartDate.CurrentValues.Add(dcStartDate);
pfEndDate.CurrentValues.Add(dcEndDate);
paramFields.Add(pfStartDate);
paramFields.Add(pfEndDate);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
//ReportDocument oRpt = new ReportDocument();
//oRpt.Load("c:\\inetput\\[URL unfurl="true"]wwwroot\\LMDashboard\\TMXCompanyDetail.rpt");[/URL]
//CrystalReportViewer1.ReportSource = oRpt;
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}