2012-10-15 26 views
0

我有一个表格,允许用户选择他们想要生成的报告。他们也可以选择标准,选择打印,预览,导出等。用户做出选择并点击“生成”按钮后,我有一个类创建报表对象,加载报表,数据集,然后打印或导出那个报告。我创建了一个单独的表单来预览报表。当我将报表对象传递给预览窗体时,我收到“无效的报表源”。报告打印和输出很好,我只是不能预览报告。我不想在预览窗体中复制代码,我希望能够传递报表对象。我的代码片段如下。有什么建议么?预览水晶报告在一个单独的表格

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" 
      } 
     } 
+0

所以我改变了预览表格,以便我不再将报告传递到窗体中,形成类。我更改了类中的方法,以在加载报告后返回ReportDocument。在我的表单中,我调用该加载方法并设置DataSource。现在,表单加载,但我得到的错误消息:方法没有找到“'Void CrystalDecisions.Shared.PageRender.set_ExceptionWIndowTitle(System.String)'。我现在试图追查下来。 – ggrewe1959

回答

0

问题已解决。我在Windows 7,64位操作系统上运行。我最初为64位Visual Studio 2010安装了Crystal Reports。看起来,您需要SP4的64位和32位版本的运行时。