0
votes

I need to integrate a Crystal Report .rpt file into my WPF application. Everything is going fine but when I added a report selection to the report it seems to wipe out the parameters. Here is the code that I am working with;

ReportClass r1 = new ReportClass();
r1.FileName = "myReport.rpt";
foreach (var t in r1.Database.Tables)
{
    CrystalDecisions.CrystalReports.Engine.Table tb = t as CrystalDecisions.CrystalReports.Engine.Table;
    tb.LogOnInfo.ConnectionInfo = conInfo;
    tb.ApplyLogOnInfo(tb.LogOnInfo);
}
CrystalDecisions.Shared.ParameterRangeValue rangeValue = new CrystalDecisions.Shared.ParameterRangeValue();
DateTime sd = (DateTime)StartDatePicker.SelectedDate;
DateTime ed = (DateTime)EndDatePicker.SelectedDate;
rangeValue.StartValue = sd;
rangeValue.EndValue = ed;
r1.SetParameterValue(r1.ParameterFields[0].Name, rangeValue);
string rs = "Correctly formated Record Section Formula"; 
r1.DataDefinition.RecordSelectionFormula = rs;
myReportViewer.ViewerCore.ReportSource = r1;

Now the record selection formula works perfectly. However it ignores the parameter value. If the r1.DataDefinition.RecordSelectionFormula = rs;is removed then the parameters work correctly. What am I doing wrong?

1
is there other code? i don't see you calling Load anywhere, so i assume there is other code. If there is, are you calling .Refresh()?Theodosius Von Richthofen
What happens when you replace ReportClass with ReportDocument for the r1 object?Theodosius Von Richthofen
@Theodosius Von Richthofen There is no more code. the myReportViewer is the CrystalReportsViewer and setting the ReportSource executes the reportXaphann
@Theodosius Von Richthofen changing it to ReportDocument didn't change anythingXaphann
why do you need "Correctly formated Record Section Formula"? this doesn't seem to be a RecordSelectionFormula that would do anythingTheodosius Von Richthofen

1 Answers

0
votes

Found the answer. Turns out that r1.DataDefinition.RecordSelectionFormula = rs; was over writing the the reports record selection. Adding this fixed it

if (rs != "")
{
    rs = r1.DataDefinition.RecordSelectionFormula + " and " + rs;
}
else
{
    rs = r1.DataDefinition.RecordSelectionFormula;
}