I have a form that allows a user to select what report they want to generate. They can also select criteria, select Print, Preview, export, etc. After the user makes their selections and clicks the "Generate" button, I have a class that creates the report object, loads the report, dataset, and then prints or exports the report. I created a separate form to preview the report. When I pass the report object to the preview form, I receive "Invalid Report Source." The report prints and exports just fine, I just cannot preview the report. I do not want to duplicate the code in the preview form, I was hoping that I could just pass the report object. Snippets of my code are below. Any suggestions?
public static class CrystalReportUtilities
{
private static ReportDocument goReport {get; set;}
private static string gsReportName { get; set; }
private static string gsSqlString { get; set; }
private static object[,] goParameters { get; set; }
public static void generateReport(parameters...)
{
goReport = loadReport();
...
goReport.SetDataSource(DataTable);
...
previewReport();
private static void previewReport()
{
CrystalReportPrintPreviewForm loReportPreview = new CrystalReportPrintPreviewForm(goReport);
loReportPreview.ShowDialog();
}
public partial class CrystalReportPrintPreviewForm : Form
{
private ReportDocument goReport;
public CrystalReportPrintPreviewForm(ReportDocument poReport)
{
InitializeComponent();
goReport = poReport;
}
private void crystalReportViewer1_Load(object sender, EventArgs e)
{
try
{
if (goReport != null)
{
crystalReportViewer1.ReportSource = goReport; // Receive "Invalid Report Source"
}
}
Problem resolved. I am running on a Windows 7, 64 bit OS. I originally installed Crystal Reports for 64 bit Visual Studio 2010. It appears that you need both, the 64 bit and 32 bit version of the runtimes, with SP4.