PRMiller2
Technical User
- Jul 30, 2010
- 123
Using VS2010 professional, C# with Crystal Reports. What is the best way to step through and debug a Crystal Report?
I have three reports that load successfully, but a fourth that loads only the report and page headers, with no data. I used the debugger to capture the SQL statement and sucessfully ran a query against the database, returning records. I have verified that the field names match the data set, and have rebuilt the report twice, to no avail.
Here's what I've got:
ReportViewer.cs:
An integer is passed to LoadReport(int r), and I have verified that the integer of 4 is passed when attempting to load this report. I removed switch cases 1 - 3 from this post for the sake of brevity.
rptProductsInUse.cs
I have three reports that load successfully, but a fourth that loads only the report and page headers, with no data. I used the debugger to capture the SQL statement and sucessfully ran a query against the database, returning records. I have verified that the field names match the data set, and have rebuilt the report twice, to no avail.
Here's what I've got:
ReportViewer.cs:
Code:
private void LoadReport(int r)
{
string sql = "";
string conn = ComplianceManager.Properties.Settings.Default.CS_DBConnectionString;
try
{
OleDbConnection connection = new OleDbConnection(conn);
switch (r)
{
case 4:
sql = "SELECT DISTINCT a.txtProductPartNumber, a.txtProductTradeName, a.txtManufacturer" +
" FROM Products a" +
" LEFT JOIN Purchases b ON a.lngProductID_pk = b.lngProductID_fk" +
" WHERE (((b.lngCustomerID_fk) Like '*') AND ((b.lngProductID_fk) Is Not Null))" +
" ORDER BY a.txtManufacturer, a.txtProductPartNumber, a.txtProductTradeName;";
OleDbDataAdapter dataAdapter4 = new OleDbDataAdapter(sql, connection);
DataSet ds4 = new DataSet();
connection.Open();
dataAdapter4.Fill(ds4, "qryProductsInUse");
rptProductsInUse rpt4 = new rptProductsInUse();
rpt4.SetDataSource(ds4);
crystalReportViewer.ReportSource = rpt4;
rpt4.SetParameterValue("Customer_Name_Param", clientName);
//rpt4.SetParameterValue("Date_Range_Param", "Period: " + string.Format("{0:MM/dd/yyyy}", fromDate) + " - " + string.Format("{0:MM/dd/yyyy}", toDate));
break;
default:
sql = "ERROR;";
break;
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Problem loading report: " + ex.Message);
}
}
An integer is passed to LoadReport(int r), and I have verified that the integer of 4 is passed when attempting to load this report. I removed switch cases 1 - 3 from this post for the sake of brevity.
rptProductsInUse.cs
Code:
namespace ComplianceManager {
using System;
using System.ComponentModel;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;
public class rptProductsInUse : ReportClass {
public rptProductsInUse() {
}
public override string ResourceName {
get {
return "rptProductsInUse.rpt";
}
set {
// Do nothing
}
}
public override bool NewGenerator {
get {
return true;
}
set {
// Do nothing
}
}
public override string FullResourceName {
get {
return "ComplianceManager.rptProductsInUse.rpt";
}
set {
// Do nothing
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section Section1 {
get {
return this.ReportDefinition.Sections[0];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section Section2 {
get {
return this.ReportDefinition.Sections[1];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section Section3 {
get {
return this.ReportDefinition.Sections[2];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section Section4 {
get {
return this.ReportDefinition.Sections[3];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section Section5 {
get {
return this.ReportDefinition.Sections[4];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.Shared.IParameterField Parameter_Customer_Name_Param {
get {
return this.DataDefinition.ParameterFields[0];
}
}
}
[System.Drawing.ToolboxBitmapAttribute(typeof(CrystalDecisions.Shared.ExportOptions), "report.bmp")]
public class CachedrptProductsInUse : Component, ICachedReport {
public CachedrptProductsInUse() {
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public virtual bool IsCacheable {
get {
return true;
}
set {
//
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public virtual bool ShareDBLogonInfo {
get {
return false;
}
set {
//
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public virtual System.TimeSpan CacheTimeOut {
get {
return CachedReportConstants.DEFAULT_TIMEOUT;
}
set {
//
}
}
public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport() {
rptProductsInUse rpt = new rptProductsInUse();
rpt.Site = this.Site;
return rpt;
}
public virtual string GetCustomizedCacheKey(RequestContext request) {
String key = null;
// // The following is the code used to generate the default
// // cache key for caching report jobs in the ASP.NET Cache.
// // Feel free to modify this code to suit your needs.
// // Returning key == null causes the default cache key to
// // be generated.
//
// key = RequestContext.BuildCompleteCacheKey(
// request,
// null, // sReportFilename
// this.GetType(),
// this.ShareDBLogonInfo );
return key;
}
}
}