C# 使用c显示crystal报表#

C# 使用c显示crystal报表#,c#,crystal-reports,report,C#,Crystal Reports,Report,我对C#比较陌生,而且我从未使用过Crystal Reports,因此如果我使用了不正确的术语,我向您道歉。我试图显示一个由某些C#代码调用的报告。通过在这里跟踪大量的线程,我成功地获得了以下代码,它确实构建了一个调试。但是,当代码运行时,它不会显示报告 代码如下: private void forAllQualitiesToolStripMenuItem_Click(object sender, EventArgs e) { CrystalReportViewer rv = new C

我对C#比较陌生,而且我从未使用过Crystal Reports,因此如果我使用了不正确的术语,我向您道歉。我试图显示一个由某些C#代码调用的报告。通过在这里跟踪大量的线程,我成功地获得了以下代码,它确实构建了一个调试。但是,当代码运行时,它不会显示报告

代码如下:

private void forAllQualitiesToolStripMenuItem_Click(object sender, EventArgs e) {
    CrystalReportViewer rv = new CrystalReportViewer();
    string reportPath = @"C:\Documents and Settings\rp\Desktop\StockByStatus.rpt"; 

    ReportDocument r = new ReportDocument();

    r.Load(reportPath);
    rv.Visible = false; // i put this in because when i ran the code without it, it said the report must not be visible and the program would fall down
    rv.ReportSource = r;
    rv.InitReportViewer();
    ShowDialog(rv);
}
现在
请尝试将此代码用作参考代码。

最好添加windows窗体并将Crystel report viwer拖放到窗体。它会自动设置为全屏。您可以使用RT report viwer查看应用程序中的所有Crystel报表。注:您需要根据我们的Visual studio安装Crystel report运行时兼容版本版本。

    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load(@"CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");
    crystalReportViewer1.ReportSource = cryRpt;
    crystalReportViewer1.Refresh();

现在,您可以在按钮按下事件中这样调用报告

 private void btOPdetailRep_Click(object sender, EventArgs e)
 {
   try
  {
    load();
    frmReports.printproparty = 7;   //7 what i assign numer for identify report
    frmReports objshow = new frmReports();
    objshow.ShowDialog();
  }
    catch (Exception ex)
  {
    MessageBox.Show("Details Printing Error!");
  }
}
然后在报告表单加载事件中编写以下代码

string username = "sa";       //USERNAME AND PASSWORD FOR REPORT LOADING
 string password = "123";
if (printproparty == 7)
  {
   ReportDocument cryRpt = new ReportDocument();
   cryRpt.Load(@"op payment.rpt");
   cryRpt.SetDatabaseLogon(username, password);
   reports.ReportSource = cryRpt;
   reports.RefreshReport();
   reports.Refresh();
  }

我与SAP打了大约6周的交道,试图让一些crystal reports的东西在.NET4.5下稳定工作。当我继续遇到问题并建议我们公司使用SSR可能会更好时,SAP的技术支持部门同意这可能是对我们更好的解决方案。克里斯托是SAP的红发继子。支持是可怕的。除非您的公司已经将巨额资金投入到SAP的口袋中,否则您也可能会得到更好的支持解决方案。感谢您的回复。我应该补充一点,这是给c#net的。所以我不认为这会起作用,因为我的解决方案中没有任何aspx文件。
string username = "sa";       //USERNAME AND PASSWORD FOR REPORT LOADING
 string password = "123";
if (printproparty == 7)
  {
   ReportDocument cryRpt = new ReportDocument();
   cryRpt.Load(@"op payment.rpt");
   cryRpt.SetDatabaseLogon(username, password);
   reports.ReportSource = cryRpt;
   reports.RefreshReport();
   reports.Refresh();
  }